我有一个GWT应用程序,我使用“GWT活动和地点”进行导航,Browserhistory等。现在我尝试合并google plus按钮,以便用户可以推荐单个特定文章。正如您在第一个屏幕截图中看到的那样,我在页脚中也有一个google plus按钮。那个直接包含在主页(HTML页面)中,并显示在第一页加载中。第二个是文章小部件的一部分,因此通过javascript添加到主机页面。这个没有显示在第一页加载,但如果我重新加载页面(请参阅按F5后的第二个屏幕截图)。有没有解决这个问题的方法?
我对facebook喜欢按钮有同样的问题。我可以通过从HTML5版本切换到iFrame版本来解决这个问题。还有另一个版本的google plus按钮吗?
这是我的代码。首先,我添加了google plus脚本:
<script type="text/javascript">
window.___gcfg = {
lang: 'en-US'
};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
此代码添加按钮:
<div class='g-plusone' data-annotation='inline' data-width='300' data-href='http://gwt-prime.appspot.com/fb/ArticleSection/4'></div>
截图:
页面的第一次加载 - &gt;按钮丢失:
重新加载页面后 - &gt;按钮显示:
示例链接
要亲自查看该页面,请查看此处:live example
答案 0 :(得分:2)
尝试在网站完全呈现后调用此jsni代码段:
/**
* Render any Google+ button inside of the container identified by containerId.
*/
static public native void go(String containerId) /*-{
$wnd.gapi.plusone.go(containerId);
}-*/;