html5 - Javascript local storage error -


how can assign javascript variable local storage variable?

here attempt:

var abc=localstorage.crabc; function tab() {     if (abc==2) {         window.open("index.html","_self")     } else {         window.open("main.html","_self")     } } tab() localstorage.crabc="2"; 

you need use localstorage.getitem() , localstorage.setitem() retrieve , store items localstorage:

var abc=localstorage.getitem('crabc');  function tab() {     if (abc=='2') {         window.open("index.html","_self")     } else {         window.open("main.html","_self")     } } tab(); localstorage.setitem('crabc', '2'); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -