Javascript 如何在iframe中加载google plus共享按钮?
有谁能给我一个解决方案,告诉我如何在iframe中异步加载googleplus共享按钮(而不是+1按钮)。我已经成功地为+1按钮执行了此操作。如果您试图在用户悬停在某个对象上时显式渲染按钮,则需要执行的操作是使用显式渲染流,如下所述: 但是,有一个问题,因为您使用的是共享按钮,所以不能使用显式渲染代码直接渲染到div。相反,您将创建共享链接,将渲染设置为显式,然后可以使用JavaScript触发共享按钮的渲染 有关守则如下:Javascript 如何在iframe中加载google plus共享按钮?,javascript,google-plus,google-plus-one,Javascript,Google Plus,Google Plus One,有谁能给我一个解决方案,告诉我如何在iframe中异步加载googleplus共享按钮(而不是+1按钮)。我已经成功地为+1按钮执行了此操作。如果您试图在用户悬停在某个对象上时显式渲染按钮,则需要执行的操作是使用显式渲染流,如下所述: 但是,有一个问题,因为您使用的是共享按钮,所以不能使用显式渲染代码直接渲染到div。相反,您将创建共享链接,将渲染设置为显式,然后可以使用JavaScript触发共享按钮的渲染 有关守则如下: <html> <head> &l
<html>
<head>
<title>+Share: Explicit render</title>
<link rel="canonical" href="http://www.example.com" />
<script type="text/javascript">
window.___gcfg = {
lang: 'en-US',
parsetags: 'explicit'
};
function renderShare() {
gapi.plus.go(); // Render all the buttons
}
</script>
</head>
<body>
<a href="#" onClick="renderShare();">Render the share control</a>
<!-- a share button that will get rendered when gapi.plus.go is called -->
<div class="g-plus" data-action="share" id="share-div"></div>
</body>
<script type="text/javascript">
// Asynchronously load the plusone script, for performance
(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>
</html>
+共享:显式渲染
窗口。\uuuuuu gcfg={
朗:“恩,我们”,
parsetags:'显式'
};
函数renderShare(){
gapi.plus.go();//渲染所有按钮
}
//异步加载plusone脚本,以提高性能
(功能(){
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);
})();
对于您来说,我猜您尝试使用不同的触发器来呈现+1按钮,而不是用户必须明确单击的按钮,您可以使用适当的事件来触发呈现。尝试以下html片段:
<iframe src="https://plusone.google.com/_/+1/fastbutton?bsv&size=medium&hl=en-US&url=http://test.com/&parent=http://test.com/" allowtransparency="true" frameborder="0" scrolling="no" title="+1"></iframe>
为什么“仅共享”按钮只需连接到网络,并通过给出src;-)在iframe中加载整个google+)@Webtecher,我想在我的博客www.webpeaks.in中使用共享按钮。我想要的是,它应该只在用户悬停在标题上方时加载。我相信谷歌正在阻止在iframe中加载共享按钮,你将无法这样做。谢谢你的回答。我会试试这个。url
和parent
之间有什么区别?