问题描述
//检测这是第一次运行
var first_run = false;
if(!localStorage ['ran_before']){
first_run = true;
localStorage ['ran_before'] ='1';
}
//如果不是,则启动intro()脚本
if(first_run)intro();
// intro script
function intro(){
window.open(intro / index.html,'_blank');
}
但遗憾的是,当我点击扩展名时, code> popup.html 但只是打开介绍页面......它需要保持 popup.html
打开,我确定有一种方法可以做到这一点。
要做到这一点,最好的方法是什么?
虽然Marc Guiselin的回答非常好,但知道如何在不关闭弹出窗口的情况下打开标签可能会很有帮助。
您可以在后台打开选项卡,这样它就不会关闭弹出窗口。
chrome。 tabs.create({
url:chrome.runtime.getURL(intro / index.html),
active:false
});
一般而言,您应该避免使用 window.open
,并使用 chrome.tabs
和 chrome.windows
API。
I have the following code to introduce my Chrome Extension.
// detect if this is the first time running
var first_run = false;
if (!localStorage['ran_before']) {
first_run = true;
localStorage['ran_before'] = '1';
}
// if not, start the intro() script
if (first_run) intro();
// intro script
function intro() {
window.open("intro/index.html", '_blank');
}
But sadly, when I click the extension, it doesn't open the popup.html
but just opens the intro page.. it needs to keep the popup.html
open and I'm sure there is a way to do this. I want to open them both at the same time.
What is the best way to do this?
While Marc Guiselin's answer is excellent, it may be useful to know how to open a tab without closing a popup.
You could open the tab in the background, that way it won't close your popup.
chrome.tabs.create({
url: chrome.runtime.getURL("intro/index.html"),
active: false
});
In general, you should avoid using window.open
in extensions and use chrome.tabs
and chrome.windows
API instead.
这篇关于打开新页面时保持打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!