如何使用API关闭Google Chrome窗口中的所有标签 [英] How I can close all tabs in Google Chrome window using API
本文介绍了如何使用API关闭Google Chrome窗口中的所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过扩展程序关闭Chrome窗口中的所有标签.现在的最佳做法是什么?你会怎么做?
I need close all tabs in Chrome window via my extension. What is the best practice now? How would you have done?
推荐答案
在背景页面中,使用chrome.tabs.query(...)获取所有标签,然后调用chrome.tabs.remove(...)要关闭它,代码将如下所示:
In your background page, use chrome.tabs.query(...) to get all tabs, then call chrome.tabs.remove(...) to close that, code will look like:
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.remove(tabs[i].id);
}
});
这篇关于如何使用API关闭Google Chrome窗口中的所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文