I'm building a chrome extension and every time the user click on the icon the popup.html page is loaded(reloaded). Is there a way to load the popup page only the first time, or to load it in the background?

Here is the code from my background script

var x=false;
chrome.browserAction.onClicked.addListener(function(tab) {
    if(x==false){
        alert("test");
        chrome.browserAction.setPopup({popup: "popup.html"});
    }
});

So the alert("text") is triggered only one time, but the popup.html is changed every time I click the icon. In popup.html I simply generate a different random number.

document.addEventListener('DOMContentLoaded', function () {
    document.getElementById("test").innerHTML=Math.random();
});

Thanks

有帮助吗?

解决方案

Everytime a users clicks the browserAction button chrome will open or close the attached popup. There is no way to stop it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top