我刚刚开始将一些社交媒体“共享”集成到网站中,第一个是 Google +1 按钮。
我直接从 Google 的网站管理员仪表板中取出代码,按照所有说明将其放入,但每当我尝试点击 +1 时,代码就会崩溃
我已将其“直播”于:
http://www.techonline.co.nz/modules/navigator/navto.php?unique_ID=16
按钮本身在这里:
<td style="width: 33%; text-align: center;">
<div class="g-plusone" data-annotation="inline" data-width="130" data-href="#">Google +1</div>
</td>
Google 的 Javascript 位于 ' 的底部
<script type="text/javascript">// <![CDATA[
(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>
CDATA 是 TinyMCE 的自动产物。也不知道它是做什么的,但它并没有阻止任何其他 Javascript 在我的网站上工作。由于按钮的显示,此实例中的代码仍然会执行。
谁能告诉我为什么它会坏掉,就像我弄错了一样
最佳答案
data-href 设置可能是问题所在。请参阅 setting the URL 上的文档。理想情况下,您可以将规范元数据添加到页面中,这在您的情况下应该会有所帮助,因为您似乎正在编写动态页面,其中 URL 可能略有不同,但仍然引用相同的资源。
另一个提示,test your page using the Webmaster rich snippets tool .
关于javascript - Google +1,每次点击都会中断。使用谷歌的代码。为什么会破,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12763139/