假设您刚刚打开 Chrome。有一个“新标签”已经打开。我的扩展程序有一个按钮,当用户按下它时,我会创建一个新选项卡来显示我的内容 (index.html)。
现在一切正常,但问题是“新标签”毫无用处。我使用以下调用来创建一个新选项卡:
chrome.tabs.create({
"url":"index.html"
});
update() 不起作用(什么也没有发生)。
chrome.tabs.update({
"url":"index.html"
});
当我检查当前选项卡时,它显示“未定义”:
chrome.tabs.getCurrent(function(t){console.log(t.id)})
如何使用当前的空选项卡而不是创建新选项卡?我发现其他一些扩展(即 Google Mail Checker )也有同样的问题。
最佳答案
显然,Tabs API 不允许您像 jQuery 那样省略前导可选参数。要更改当前选项卡,您需要显式包含 null
作为 update()
的第一个参数 (tabId):
chrome.tabs.update(null, {
"url":"index.html"
});
关于javascript - Chrome API : how to use the current empty "New Tab" instead of creating another one?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10075667/