By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

can we set a variable value in a script alive even after page reload?

P: 3
I mean can set a variable value in a script to be unchanged even after page reload?
for example if i set a value of a global variable "val" to 2 ; so using onbeforeunload() or onunload(), i will change the value of variable "val" to 5;
so can i in anyway get the value of variable "val" equal to 5? after loading the page..,i mean after onload() event is done/

does my question make any sense?

thnx..
Jan 23 '08 #1
Share this Question
Share on Google+
1 Reply


P: 7
I mean can set a variable value in a script to be unchanged even after page reload?
for example if i set a value of a global variable "val" to 2 ; so using onbeforeunload() or onunload(), i will change the value of variable "val" to 5;
so can i in anyway get the value of variable "val" equal to 5? after loading the page..,i mean after onload() event is done/

does my question make any sense?

thnx..
No. If you want to keep variables between different pages you need to do one of these things:

1) pass the variable as a parameter to the page
2) store the variable in the session
3) change how your page is constructed so that it uses ajax to reload only the parts of the page that you need reloaded, thereby preserving the state of the javascript in your page

I think that options 1 and 2 will require you to have an intelligent back end of some sort (php, asp.net, java), although maybe there is some way to modify the session with purely javascript. Option number 3 is probably the way to go if you are only dealing with normal html files and no real intelligent back end. Of course, whether option 3 is really an option depends on your specific project.
Jan 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.