2

要在您的网站上添加 Google 的 plusone 按钮,需要插入以下脚本标记(用于显式加载)。

<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  {"parsetags": "explicit"}
</script>

它在 HTML 中看起来非常简单。但是我不想使用 JS 文件插入脚本。所以我使用以下代码:

var e = document.createElement('script');
e.src = "https://apis.google.com/js/plusone.js";
e.id = "googplusonescript";
e.innerHTML = '{"parsetags": "explicit"}';
document.getElementsByTagName("head")[0].appendChild(e);

它在除 IE 之外的所有浏览器中都非常棒,因为 IE 不允许我们编写脚本标签的 innerHTML。任何人都可以解决吗?(我在页面中插入了 jquery。所以也可以使用 jquery。)

4

4 回答 4

5

遇到了同样的问题。在 IE 下你应该使用脚本。text = '{"parsetags": "explicit"}'; 而不是 script.innerHTML

于 2011-07-12T06:50:54.337 回答
1

尝试创建一个 textNode 并将其附加到您的脚本标签:

var myText = document.createTextNode('{"parsetags": "explicit"}'); 
myScriptTag.appendChild(myText);
于 2011-07-02T06:40:52.037 回答
0

尝试以下操作:

window['___gcfg'] = { parsetags: 'explicit' };
于 2013-01-21T18:44:23.033 回答
-1
var ispoloaded;

function showpo() {
var pohd = document.getElementsByTagName('head')[0];
var poscr = document.createElement('script');
poscr.type ='text/javascript';
poscr.async = true;
poscr.text ='{"parsetags": "explicit"}'; //works on IE too
poscr.src = "http://apis.google.com/js/plusone.js";
pohd.appendChild(poscr);


ispoloaded = setInterval(function () {


//check if plusone.js is loaded
if(typeof gapi == 'object') {
//break the checking interval if loaded
clearInterval(ispoloaded);
//render the button, if passed id does not exists it renders all plus one buttons on page
gapi.plusone.go("idthatexists");
}

}, 100); //checks every 0.1 second



}
于 2011-10-31T04:47:13.307 回答