Chrome扩展程序:2个打开的窗口中的活动选项卡是什么? [英] Chrome Extension: What is the active tab in 2 opened windows?

查看:151
本文介绍了Chrome扩展程序:2个打开的窗口中的活动选项卡是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展程序,需要知道活动选项卡上的URL,但是问题是,当我打开第二个Chrome窗口时,有2个活动选项卡,在网站管理员工具中,它没有任何提示我实际上在哪个窗口上. 截屏时,我实际上是在第二个窗口上.

I have an extension that needs to know what URL is on the active tab, but the problem is that when I open a second chrome window there are 2 active tabs, in the webmaster tools it doesn't give me any indication of what window I'm actually on. I was actually on the 2nd window when I took this screenshot.

我正在使用的代码是:

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

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

But the good code would have been app.tabInfo = tabs[1]; but I need to know that I need to pick that one. So how can I know?

谢谢.

推荐答案

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

Make your query to select the last focused Window:

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

注意:最好不要服用currentWindow: true,因为:

Note: Better don't take currentWindow: true because:

当前窗口是包含当前正在执行的代码的窗口.重要的是要意识到这可能与最上面的窗口或聚焦的窗口不同.

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

这篇关于Chrome扩展程序:2个打开的窗口中的活动选项卡是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆