global variables doesn't change value in Javascript
- by user1856906
My project is composed by 2 html pages: 
 1)index.html, wich contains the login and the registration form.
 2)user_logged.html, wich contains all the features of a logged user.
Now, what I want to do is a control if the user is really logged, to avoid the case where a user paste a url in the browser and can see the pages of another user. 
hours as now, if a user paste this url in the browser: 
 www.user_loggato.html?user=x#profile
is as if logged in as user x and this is not nice.
My html pages both use js files that contains scripts. 
I decided to create a global variable called logged inizialized to false and change the variable to true when the login is succesfull.
The problem is that the variable, remains false.
here is the code:
 var logged=false; (write in the file a.js)
while in the file b.js I have:
 function login() {
 //if succesfull
        logged=true;
       window.location.href = "user_loggato.html?user="+ JSON.parse(str).username + #profilo";
Now with some alerts I found that my variable logged is always false. Why?
if I have not explained well or if there is not some information in order to respond to my question let me know.