gpt4 book ai didi

google-chrome - Chrome 扩展 : What is the active tab in 2 opened windows?

转载 作者:行者123 更新时间:2023-12-01 08:32:26 26 4
gpt4 key购买 nike

我有一个扩展程序需要知道事件选项卡上的 URL,但问题是当我打开第二个 chrome 窗口时有 2 个事件选项卡,在网站管理员工具中它没有给我任何关于我的窗口的指示真的在。
enter image description here
当我截取这张截图时,我实际上在第二个窗口。

我正在使用的代码是:

chrome.tabs.query({'active': true}, function (tabs) {
app.tabInfo = tabs[0];
});

但是好的代码应该是 app.tabInfo = tabs[1];但我需要知道我需要选择那个。那我怎么知道?

谢谢你。

最佳答案

进行查询以选择最后一个焦点窗口:

chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
//...
});

注意:最好不要带 currentWindow: true因为:

The current window is the window that contains the code that is currently executing. It's important to realize that this can be different from the topmost or focused window.



来源: http://developer.chrome.com/extensions/windows.html#current-window

关于google-chrome - Chrome 扩展 : What is the active tab in 2 opened windows?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17076408/

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