Chrome扩展程序是否可以关闭用户打开的当前标签页?如果是这样,我该怎么做?
是的,Chrome扩展程序当然可以关闭当前打开的标签页。该API是chrome.tabs.remove()
。
您必须提供您希望关闭/删除的选项卡ID或选项卡ID数组作为第一个参数。第二个可选参数是一个回调函数,该选项卡在删除选项卡后即被调用。
如果要关闭当前窗口中的活动选项卡,则可能需要先获取该信息。您可以使用chrome.tabs.query()
。代码如下:
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
//'tabs' will be an array with only one element: an Object describing the active tab
// in the current window. To remove the tab, pass the ID: to chrome.tabs.remove().
chrome.tabs.remove(tabs[0].id);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句