我正在构建一个应用程序。我想在其中关闭当前浏览器选项卡,并且我想专注于我将通过的 url 选项卡。如果浏览器包含具有该 url 的选项卡,则该选项卡应聚焦,如果浏览器不包含具有该 url 的选项卡,则应打开一个新窗口。对于关闭当前选项卡,它正在工作window.close()
,但我应该怎么做才能专注于一个选项卡。
问问题
1328 次
1 回答
1
尝试这个:
// Getting a list of tabs of the current window.
chrome.windows.getLastFocused(
// Without this, window.tabs is not populated.
{populate: true},
function (window)
{
var foundSelected = false;
for (var i = 0; i < window.tabs.length; i++)
{
// Finding the selected tab.
if (window.tabs[i].active)
{
foundSelected = true;
}
// Finding the next tab.
else if (foundSelected)
{
// Selecting the next tab.
chrome.tabs.update(window.tabs[i].id, {active: true});
return;
}
}
});
于 2015-06-17T03:23:26.127 回答