jquery - Saving a state within a javascript function -


i have ruby on rails web application uses javascript function update component on page.

all want have web site 'remember' value when user reloads page and/or returns after re-loading.

the javascript simple. want this...

$('#my_field').change(function() {   $('#result').html = 'a new value' }); 

only have 'result' component retain 'a new value' after user reloads page.

any suggestions?

thanks!

i suggest using html5 local storage so:

this store value in local storage localstorage.setitem('value','a new value');

you can value so: var oldvalue = localstorage.getitem('value');

this work cookies, done client side!

in example can use this:

$('#my_field').change(function() {   localstorage.setitem('value',$('#result').val()); }); 

when go page again after refresh can value:

var oldvalue = localstorage.getitem('value'); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -