[英]Javascript, Chrome Extension development, close popup
In my manifest i have this:在我的清单中,我有这个:
"popup": "1_options.html"
and in the above html file I have this code在上面的 html 文件中我有这个代码
var saved_email = localStorage['saved_email'];
if (saved_email !== undefined || saved_email != "a@a.com")
{
chrome.tabs.create({url: '0_register.html'});
}
which is working exactly as I want, it opens a new tab with the register.html BUT it still has the popup open on the top right:( (1_options.html)
这完全符合我的要求,它会打开一个带有寄存器的新选项卡。html 但它仍然在右上角打开了弹出窗口:(
(1_options.html)
is there anyway to close the popup automatically as I open this new tab?当我打开这个新标签时,是否有自动关闭弹出窗口?
Thanks!谢谢! Ryan
瑞安
Have you tried:你有没有尝试过:
self.close();
There's several ways to do this, but the easiest is just to call:有几种方法可以做到这一点,但最简单的方法是调用:
window.close();
You can even do this in a callback function when you create your tab...您甚至可以在创建选项卡时在回调 function 中执行此操作...
chrome.tabs.create({url: '0_register.html'}, function() {
window.close();
});
You could also add a listener in your background script to check for tab updates, and if your new tab is your registration window, you could remove the popup:您还可以在后台脚本中添加一个侦听器来检查选项卡更新,如果您的新选项卡是您的注册 window,您可以删除弹出窗口:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status == "loading") {
if(tab.url == "chrome-extension://[extension-id]/0_register.html") {
chrome.tabs.remove(tabId);
}
}
});
chrome.tabs.create({url: '0_register.html', selected: true});
If you don't mind the new tab being selected when it is created, this also forces the popup to close.如果您不介意在创建新选项卡时选择它,这也会强制弹出窗口关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.