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
4 Answers
Reset to default 4Just 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
版权声明:本文标题:javascript - Session lost window.location.href - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628031a2389194.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论