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](
相关问题