2011-08-09 35 views
3

我在玩新的Google +1按鈕,我試圖設置一個簡單的演示。Google +1按鈕腳本不在本地html文件中加載

這是我的代碼:

<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> 

但是它並沒有顯示該按鈕並沒有在我的控制檯錯誤消息。

這裏是我的Firebug淨面板的screengrab:

screenshot

任何人都知道爲什麼會這樣?

回答

2

它不會工作,因爲從Firefox 3開始,您不能在本地運行外部JS腳本。或者更確切地說,當firefox在url中看到「file://」時,你會遇到問題。這個問題也回答了here。如果您使用其他瀏覽器,它可能會工作。

如果你真的需要這種東西在本地工作,但是,有一個解決方案。您可以安裝WAMPXAMPP來運行本地服務器。