javascript - Keeping a user-defined JScript variable after reload? -


in html document, button displayed, , it's onclick event alert variable countervar. button can used bring countervar using countervar++. countervar never defined in jscript document, because want countervar stay how last defined user. expected, countervar nil after each reload. saving browser cookies not work, because same variable has displayed each user views document. i'm looking "global variables" answer, no luck. help?

as suggested in comments, can use localstorage achieve part of want:

var counter;  // save local storage window.localstorage.setitem("counter", counter); // can call whenever make changes counter variable  // load local storage // call when page loads if( window.localstorage.getitem("counter") === null){     counter = 0; } else{     counter = parseint(localstorage.getitem("counter")); } 

this allow save variable 1 user. if want share between users, can't done using client side scripting. you'll have have sort of server storage/database.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -