【发布时间】:2016-08-20 15:31:55
【问题描述】:
我想在我的网站上添加一个 Google+ 徽章。当我从 Google 配置工具复制/粘贴代码时,徽章不起作用。我认为问题可能出在 JavaScript 中,所以我创建了一个空 index.html 并复制/粘贴 Google 代码……但它仍然无法正常工作:
谷歌代码:
<!-- Place this tag in your head or just before your close body tag. -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- Place this tag where you want the widget to render. -->
<div class="g-page" data-width="250" data-href="https://plus.google.com/110789175777197362579" data-theme="dark" data-rel="publisher"></div>
index.html 中的完整 HTML
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<!-- Place this tag where you want the widget to render. -->
<div class="g-page" data-width="250" data-href="https://plus.google.com/110789175777197362579" data-theme="dark" data-rel="publisher"></div>
<!-- Place this tag in your head or just before your close body tag. -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
</body>
</html>
在控制台中我可以看到以下错误:
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。人
- 不推荐使用 getAttributeNode()。请改用 getAttribute()。 rs=AGLTcCOasCY_GkJWPJtHt2mUGUYuzPzTCg%20line%209%20%3E%20eval:34:434
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。人
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
- 在“DOMWindow”上执行“postMessage”失败:提供的目标源(“null”)与接收窗口的源(“null”)不匹配。 postmessageRelay
【问题讨论】:
-
Works fine for me. 你是想把它放在 iframe 中还是什么的?
-
嗯...我使用完全相同的 html 代码,就像我在这里发布的一样...但不起作用。我尝试了 Firefox、Firefox Developer 和 Chrome。不工作:-(
标签: javascript html google-plus badge