[英]Changing the window title when focussing the window doesn't work in Chrome
[英]Getting URL when window refreshed doesn't work in Chrome Extension
当我在Chrome扩展程序中刷新网页时,我想获取当前窗口的URL。这是我所做的:
我manifest.json的一部分:
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["temp.js"]
}
]
我的temp.js:
chrome.tabs.getSelected(null, function(tab)
{ var tabId = tab.id;
tabUrl = tab.url;
alert(tabUrl);
});
但这是行不通的。
请帮助..我仍然是初学者x)
chrome.tabs
在内容脚本中不可用。 您应该创建一个这样的后台脚本:
包括在manifest.js中:
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs"
]
然后在background.js中:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// This will give you the url if it's changed
alert(changeInfo.url);
// Or to always get the tab's url even when it's unchanged
alert(tab.url);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.