谷歌加一按钮不显示
我正在尝试向我的网站添加 Google +1 按钮。
我已按照此处的说明进行操作: http://www.google.com/intl/en/ webmasters/+1/button/index.html
这是我的网页的代码:
<html>
<head>
<title>
Why won't it appear?
</title>
<!-- Place this tag in your head or just before your close body tag -->
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
</head>
<body>
<h1>
Example title
</h1>
<!-- Place this tag where you want the +1 button to render -->
<g:plusone size="tall" href="http://www.example.com/"></g:plusone>
</body>
</html>
如您所见,我完全按照他们的指示进行操作,但它没有出现。我已经在 Chrome、Firefox 和 IE8(全部在 Windows XP 上)上尝试过。我只是从本地系统打开网页。
有趣的是,我可以看到它在这里工作 http://www.satinbow.co.uk/xxtest.html< /a>
谁能解开这个谜团?
更新/线索
当页面存储在本地系统上时,它不起作用(硬刷新也无法修复它。)
但我已将页面放在这里: dl.dropbox.com/u/6920023/test2.html 它似乎在那里工作。
知道发生了什么事真是太酷了:)
I'm trying to add a Google +1 button to my website.
I have followed the instructions here:
http://www.google.com/intl/en/webmasters/+1/button/index.html
This the code for my webpage:
<html>
<head>
<title>
Why won't it appear?
</title>
<!-- Place this tag in your head or just before your close body tag -->
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
</head>
<body>
<h1>
Example title
</h1>
<!-- Place this tag where you want the +1 button to render -->
<g:plusone size="tall" href="http://www.example.com/"></g:plusone>
</body>
</html>
As you can see, I've followed their instructions exactly, and yet it does not appear. I've tried it on Chrome, Firefox and IE8 (all on Windows XP). I'm just opening the webpage from my local system.
Interestingly I can see it working here http://www.satinbow.co.uk/xxtest.html
Can anyone solve the mystery?
Update / clues
When the page is stored on my system locally, it doesn't work (hard refreshing didn't fix it either.)
But I've put the page here: dl.dropbox.com/u/6920023/test2.html and it seems to work there.
It would be really cool know what's going on :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这是因为当它是本地(不是网络服务器)时,浏览器会阻止 JS 脚本(外部托管)以防止安全漏洞。这就是为什么它不起作用
链接:http://ejohn.org/blog/tightened -本地文件安全/
I think it's because when it's local (not webserver) browser block the JS script (that's hosted externally) to prevent security breach. That's why it doesn't work
Link: http://ejohn.org/blog/tightened-local-file-security/
另一件需要检查的事情是您是否有任何活动的广告拦截器。这些可以禁用 +1 按钮并将包含该按钮的 iframe 移出屏幕。
Another thing to check for is whether you have any ad blockers active. These can disable the +1 button and move the iframe containing the button out of the screen.
致力于我的开源项目,http://code.google.com/p/gwt-socialmedia< /a>,
我发现了另一个可能导致 +1 按钮无法呈现的原因:您忘记定义“+1 的 URL”:它必须是可访问网站的有效 URL (所以 http://localhost 不起作用 IE)。
事实上,PlusOne API 似乎连接到网站 URL,以便获取有关它的一些元数据(如描述、标题等)。
如果您没有定义 URL,Google 会向您发送错误 HTTP 400 (错误请求),带有内部消息:“在此服务器上找不到请求的 URL。”
并且该按钮不会出现...
希望它有帮助!
Working on my open source project, http://code.google.com/p/gwt-socialmedia,
i have discovered another reason that can cause the +1 button not to render: You forgot to define the "URL to +1": It must be a valid URL to an accessible website (so http://localhost won't work for i.e.).
Indeed, the PlusOne API seems to connect to the site URL, in order to get some metadata about it (like the description, title, etc)
If you don't define the URL, Google will send you an error HTTP 400 (Bad Request), with the internal message : "The requested URL was not found on this server. "
and the button will not appear...
Hope it helps!
由于浏览器安全性(如其中一个答案中提到的),它不会显示该按钮。当您的文件位于本地时,仍然要显示 google plus 按钮,请使用本地网络服务器(WAMP/XAMPP),或者您可以使用 PHP 本地服务器 https://www.sitepoint.com/take-advantage-of-phps-built-in-server/ 将文件托管在您的计算机上,并且您将看到显示的按钮在你的文件中。
Due to browser security(as mentioned in one of the answer) it would not display the button. Still to display google plus buttons when your file is local use local web server(WAMP/XAMPP) or you may use PHP local server https://www.sitepoint.com/taking-advantage-of-phps-built-in-server/ to host your file on your computer and you will see the button displayed in your file.