gpt4 book ai didi

javascript - Chrome API : how to use the current empty "New Tab" instead of creating another one?

转载 作者:行者123 更新时间:2023-11-29 22:25:00 26 4
gpt4 key购买 nike

假设您刚刚打开了 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 作为第一个参数 (tabId) 包含在 update() 中:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com