Is there a way that we can initialize only once in the chrome extension?

I am trying to write a simple chrome extension using html5 local storage. I use one index variable, which is automatically incremented every time a new value is added to local storage.

But when I load the action of the Chrome browser, it initializes this variable to 0.

Can we declare any variable only once in browser action.

PS I'm new to chromium

Thank you in advance

+3
source share
1 answer

, popup.html, . , , , , .

Backgorund →

localStorage.

: ,

var counter = 0;
function incCounter(){
    window.counter++;
}

popup.html :

var bgp = chrome.extension.getBackgroundPage();
bgp.incCounter();

+4

All Articles