我想在我的網站上添加Google+徽章。當我從Google配置工具複製/粘貼代碼時,徽章不起作用。我想這個問題可能是在JavaScript,所以我創建了一個空的index.html和複製/粘貼谷歌代碼...但它仍然不能正常工作:無法使用Google代碼在'DOMWindow'上執行'postMessage'
谷歌代碼:
<!-- 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>
FULL HTML index.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>
在控制檯中,我可以看到以下錯誤:
- 無法執行 '的postMessage' 上' DOMWindow':提供的目標原點('null')與收件人窗口的原點('null')不匹配。人
- 不贊成使用getAttributeNode()。改用getAttribute()。 '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
[適用於我。](https://jsfiddle.net/b9x4svf9/)你想把它放在iframe或其他東西? –
嗯......即時通訊使用完全相同的HTML代碼,就像我在這裏發佈的......並不起作用。我曾嘗試Firefox,Firefox Developer和Chrome。不能正常工作:-( – steelbull
[Javascript中的Google API]的可能重複(http://stackoverflow.com/questions/21710842/google-api-in-javascript) –