javascript - retain a JQuery Variable value over multiple postbacks -


i want have boolean variable retain value if page reloads in jquery. here doing.

    var timedout = false; alert("time out value = " + timedout); if (!timedout) {     //do processing , stay on same page     timedout = true;     // redirect current page using window.location.href on session timeout  } 

the value of timedout setting in loop false, , if statement true. want load once false , once set true should retain value. using decide if need redirect home page or not.

not sure if can via jquery.

try use cookie library trick, https://github.com/js-cookie/js-cookie

cookies.set('timeout', 'false'); var timeout = cookies.get('timeout'); alert("time out value = " + timedout); if (!timedout) {     //do processing , stay on same page    cookies.set('timeout', 'true');     // redirect current page using window.location.href on session timeout  } 

i replace code , added cookie functionality know better logic.

i hope helps.


Comments