我如何使用chrome.tabs.onUpdated.addListener? [英] How do I use chrome.tabs.onUpdated.addListener?
本文介绍了我如何使用chrome.tabs.onUpdated.addListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为Chrome创建一个扩展程序。我希望每当用户从一个标签移动到另一个标签时,或者当用户在标签中输入一个新的URL时,都会在页面URL中显示alert()。
I am creating an extension for Chrome. I want to show an alert() with the page URL whenever the user moves from one tab to another, or when the user enters a new URL in a tab.
无法正常工作:
This is not working:
chrome.tabs.onUpdated.addListener(function(integer tabId, object changeInfo, Tab tab) {
alert(changeInfo.url);
});
chrome.tabs.onActivated.addListener(function(object activeInfo) {
// also please post how to fetch tab url using activeInfo.tabid
});
推荐答案
删除整数
, object
和 Tab
在函数签名中。
Remove integer
, object
and Tab
in the functions signature.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
alert(changeInfo.url);
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
// how to fetch tab url using activeInfo.tabid
chrome.tabs.get(activeInfo.tabId, function(tab){
console.log(tab.url);
});
});
这篇关于我如何使用chrome.tabs.onUpdated.addListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文