Javascript Chrome扩展-使用tabId更新某些选项卡
我有一个chrome扩展,当用户按下图标时,它将当前Javascript Chrome扩展-使用tabId更新某些选项卡,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我有一个chrome扩展,当用户按下图标时,它将当前tab.id存储在一个变量中,然后在2分钟后运行chrome.tabs.executeScript功能。据我所知,我的代码应该可以工作,但我得到一个错误: 未捕获错误:参数1的值无效。属性“tabId”:意外属性 更新 chrome.tabs.update(整数tabId、对象更新属性、函数回调) 修改选项卡的属性 以下是我目前的代码: //Up here is the logic for handling the icon press
tab.id
存储在一个变量中,然后在2分钟后运行chrome.tabs.executeScript
功能。据我所知,我的代码应该可以工作,但我得到一个错误:
未捕获错误:参数1的值无效。属性“tabId”:意外属性
更新
chrome.tabs.update(整数tabId、对象更新属性、函数回调)
修改选项卡的属性
以下是我目前的代码:
//Up here is the logic for handling the icon press
chrome.tabs.query({ active: true, currentWindow: true }, function(arrayOfTabs) {
var activeTab = arrayOfTabs[0].id; //this is the active tab id.
setInterval(function() { //Interval for every 2 minutes
chrome.tabs.update({
tabId: activeTab, //this is where I get an error... What's wrong with this?
active: true,
url: "https://mywebsite.com/" + myarray[count]
}, function(tab) {
chrome.tabs.executeScript(tab.id, {
file: "function/jquery.min.js",
runAt: "document_end"
});
chrome.tabs.executeScript(tab.id, {
file: "function/code.js",
runAt: "document_end"
});
})
count++;
}, timer);
});
我的代码有什么问题吗?我试过tabId:activeTab
,也试过activeTab
,但总是出错。如何指定要更新的选项卡。更新选项卡?谢谢。您应该使用
chrome.tabs.update(activeTab, {
active: true,
url: "https://mywebsite.com/" + myarray[count]
}, function(tab){});`
tabId
和updateProperties
是两个不同的参数。您应该使用
chrome.tabs.update(activeTab, {
active: true,
url: "https://mywebsite.com/" + myarray[count]
}, function(tab){});`
tabId
和updateProperties
是两个不同的参数。很好,这很有效。非常感谢。“我会批准的,”凯蒂,对不起,我不太清楚你的要求。你说的“tabs.update
不会让我离开当前选项卡”是什么意思?没什么,我解决了这个问题。我对active:true
这件事感到困惑。太好了,这很有效。非常感谢。“我会批准的,”凯蒂,对不起,我不太清楚你的要求。你说的“tabs.update
不会让我离开当前选项卡”是什么意思?没什么,我解决了这个问题。我对active:true
这件事感到困惑。