我正在构建一个应用程序。我想在其中关闭当前的浏览器选项卡,并且我想关注我将传递的 url 选项卡。如果浏览器包含具有该 url 的选项卡,则应聚焦该选项卡;如果浏览器不包含具有该 url 的选项卡,则应打开一个新窗口。
要关闭当前选项卡,它可以运行 window.close()
但我应该怎么做才能将焦点放在选项卡上。
最佳答案
试试这个:
// 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;
}
}
});
关于javascript - 关闭当前浏览器选项卡并关注特定 url 的浏览器选项卡 - javascript/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27737756/