嗨,我想从 google plus 加载评论。人们通过我的网站在 google plus 上发布了哪些内容。 我实际上刚刚在 WordPress 博客文章中安装了这段代码。如果用户想要通过单击 Google+ 按钮来从 Google+ 加载代码并加载评论来回复帖子。
<button onClick="showGoogle();">Google+</button>
<div style="max-width:100%" id="loading">
<div id="gpcomments" style="max-width:100%"></div>
</div>
<script>
gapi.comments.render('gpcomments', {
href:'http://findsgood.com/?p=43224',
width: '682',
first_party_property:'BLOGGER',
view_type: 'FILTERED_POSTMOD','callback' : function showGoogle() {src='https://apis.google.com/js/plusone.js';}});
</script>
最佳答案
plusone.js
正在异步加载,但 gapi
正在同步调用。 gapi
在 plusone.js
加载完成之前不可用。您可以使用 onload
事件等待 gapi
可供使用。
<button onClick="showGoogle();">Google+</button>
<div style="max-width:100%" id="loading"><div id="gpcomments" style="max-width:100%"></div></div>
<script>
function showGoogle() {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://apis.google.com/js/plusone.js';
script.onload = function() {
gapi.comments.render('gpcomments', {
href:'http://findsgood.com/?p=43224',
width: '682',
first_party_property:'BLOGGER',
view_type: 'FILTERED_POSTMOD'
});
}
head.appendChild(script);
}
</script>
关于javascript - 单击加载 Google plus javascript 以显示评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484050/