开发者

Google +1 Button script not loading in local html file

开发者 https://www.devze.com 2023-03-27 01:21 出处:网络
开发者_开发问答I\'m playing around with the new Google +1 button and I\'ve attempted to set up a simple demo of it.
开发者_开发问答

I'm playing around with the new Google +1 button and I've attempted to set up a simple demo of it.

This is my code:

<html>
<head>
<title>Plus One</title>
</head>
<body>

<!-- Place this tag where you want the +1 button to render -->
<g:plusone callback="plus_one_callback" href="http://www.testurl.com/"></g:plusone>

<!--  Place this tag after the last plusone tag -->
<script type="text/javascript">
  (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);
  })();

function plus_one_callback(){
    alert('callback');
}
</script>


</body>
</html>

However it does not render the button and there is no error message in my console.

Here is a screengrab of my firebug net panel:

Google +1 Button script not loading in local html file

Anyone know why this happens?


It won't work because as of Firefox 3 you can't run external JS scripts locally. Or to be more exact, you'll run into problems when firefox sees "file://" in the url. This question was also answered here. It probably would work if you used another browser.

If you really need this kind of stuff to work locally, however, there is a solution. You can install WAMP or XAMPP to run a local server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号