admin管理员组

文章数量:1295928

I'm trying to redirect the user to another page width:

window.location.href = "url here" //relative link

but when I do, it clears my sessvars.keyPageArray variable. Anyone know how to keep a session variable after a redirect?

This is the sessvars library that I am using: .html

UPDATE: I used google chrome debugger and my script actually does work. For some crazy reason it only works if I'm monitoring it variable by variable but not when I simply run it normally without the debugger on? Why is that happening?

I'm trying to redirect the user to another page width:

window.location.href = "url here" //relative link

but when I do, it clears my sessvars.keyPageArray variable. Anyone know how to keep a session variable after a redirect?

This is the sessvars library that I am using: http://www.thomasfrank.se/sessionvars.html

UPDATE: I used google chrome debugger and my script actually does work. For some crazy reason it only works if I'm monitoring it variable by variable but not when I simply run it normally without the debugger on? Why is that happening?

Share Improve this question edited Jul 17, 2012 at 18:14 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Jul 17, 2012 at 16:15 user1410668user1410668 2454 gold badges6 silver badges16 bronze badges 1
  • I posted the libary in the OP. I also have an update. Something really weird is going on. – user1410668 Commented Jul 17, 2012 at 18:12
Add a ment  | 

4 Answers 4

Reset to default 4

Just because you named a variable sessvars doesn't make it so. Use localStorage, sessionStorage or cookies depending on your need.

All javascript context is unloaded and lost when the browser navigates to another page.

Example using localStorage:

window.onbeforeunload = function() {
    localStorage.setItem( "session", JSON.stringify( window.sessvars) );
};

window.onload = function() {
    window.sessvars = JSON.parse( localStorage.getItem( "session") || "{}" );;
};

Sessions are on the server side.

Nothing to do with the browser.

JavaScript doesn't keep data after the page is closed, to open anoher page, or eaven on refresh. Eventualy you can store data in cookie.

One important thing causing the problem is when in server /phptmp directory does not exist or does not have writing permissions.

本文标签: javascriptSession lost windowlocationhrefStack Overflow