如何关闭当前的扩展标签? [英] How to close the current extension tab?

查看:150
本文介绍了如何关闭当前的扩展标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图关闭扩展程序的选项页面。
我有一个Cancel按钮,我使用这段代码:

I'm trying to close the Options page of the extension. I have a Cancel button and I'm using this code:

chrome.tabs.getCurrent(null, function(tab) {
  chrome.tabs.remove(tab.id, function() {});
});

当我尝试使用它时,它总会出现此错误:

When I'm trying to use it, it always gives this error:

Uncaught TypeError: Cannot call method 'getCurrent' of undefined

代码有什么问题?

推荐答案

p>

It works for me with one little fix:

chrome.tabs.getCurrent(function(tab) {
    chrome.tabs.remove(tab.id, function() { });
});

只要确保您真的在扩展的选项页中运行此代码,而不仅仅是一些HTML页面,因为chrome.tabs API仅适用于扩展。

Just make sure you're really running this code in options page of your extension and not just some HTML page, because chrome.tabs API is available only for extensions.

这篇关于如何关闭当前的扩展标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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