0

我創建一個Chrome擴展,用下面的代碼在Chrome擴展中,如何通過browser_action(popup.html)獲取網站的網址?

manifest.json的:

{ 
"name": "Project", 
"version": "1.0.0", 
"manifest_version": 2, 
"description": "Popup when website requires Log in", 
"browser_action":{ 
    "default_icon":"icon_19.png", 
    "default_popup":"Popup.html" 
} 
} 

Popup.html:

<html> 
<head></head> 
<body> 
<div class="plus" id="plu"></div> 
<script src="inline.js"></script> 
</body> 
</html> 

inline.js:

window.onload = function() { 
document.getElementById('plu').onclick=popup; 
} 
function popup() { 
var link = document.URL; 
alert("This is the Link : (" +link+ ")"); 
} 

當我點擊ID爲'plu'的div時,它會得到popup.html的URL,但是n ot爲網站。請幫助。謝謝 。

+0

可能重複http://stackoverflow.com/questions/1979583/how-can-i-get -the-URL-FOR-A-谷歌鉻選項卡) – CBroe

回答

0

此時的文檔對象引用了您的擴展的彈出窗口,因爲您在popup.html中包含腳本。

如果您想訪問標籤頁面的DOM,則需要使用內容腳本。看一看:

http://developer.chrome.com/extensions/content_scripts.html

的[?我怎樣才能得到一個谷歌瀏覽器選項卡中的URL](
相關問題