I have a js file test.js that contains a global variable global_var and a function fn1() that changes the variable global_var:
var global_var="initial_value";
function fn1(){
global_var="Value1";
alert("global_var="+global_var);
}
then I execute the fn1() from my page1.html that sends me to page2.html:
<li><a href="page2.html" onclick='fn1();'></a></li>//this returns "global_var=Value1"
Then, in page2.html I want to use the variable global_var, but the continous of global_var is not changed, it’s “initial_value”!!
<script src="test.js"></script>
<script>
$('#mypage').live('pageshow', function(event) {
alert(global_var); //this returns "initial_value"!!!
});
</script>
You dont call the function in page2. Every time you load to an other page your JS will reset… Save it in a SESSION or locally for example if you want to keep it alive!