<script type="text/javascript>
var x = 0; //this occurs in the beginning of the page.
$("#button").onclick{
x = 1;
}
</script>
Let's say the variable "x" changes to 1. Then the user clicks a link. When the user clicks "back", will x be 0 or 1?
<script type="text/javascript>
var x = 0; //this occurs in the beginning of the page.
$("#button").onclick{
x = 1;
}
</script>
Let's say the variable "x" changes to 1. Then the user clicks a link. When the user clicks "back", will x be 0 or 1?
It will be0
. The browser does not cache the state of Javascript variables between page loads.Update
This is not the case in browsers such as Firefox. Please see Trey's answer.
As detailed in another question, the real answer to this question is it depends on the browser.
In Firefox and Opera, the below page will preserve the state of
1
if Set x is clicked, the link is clicked, and then the back button is pressed. However, in Chrome and IE6 the page will be reloaded andx
will have the value of0
.