Javascript onunload 在新页面加载后发生
在我的网站中,我尝试将某个页面限制为每个用户只能有一个会话,为此我使用了 cookie(不能使用 Session 变量)和母版页中 body 元素的 onunload"
事件- 我删除了 cookie,并在特定 Web 部件的 CreateChildControl
中检查 cookie/如果不存在则创建它
问题是,当我从一个页面移动到另一个页面时 - <代码>创建子控件发生在上一页的 onunload
事件之前,这很奇怪 - cookie 仍然存在,因为它尚未被上一页删除
。
In my website I try to limit a certain page to one session per user only, to do so I used cookies (can't use Session variable) and the onunload"
event of the body element in the masterpage- there I delete the cookie and in CreateChildControl
of the specific webpart I check for the cookie/create it if it doesn't exist.
The problem is that when I move from one page to another- the createchildcontrols
occurs before the onunload
event of the previous page which is weird- what happens is that the cookie still exists because it hasn't been deleted by the previous page yet.
How do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Onunload 不可靠并且不应用于任何重要目的。如果浏览器崩溃等怎么办?
如果您想限制每个用户一个会话,只需在由于某种原因创建新会话时删除/使旧会话失效即可。
Onunload is not reliable and should not be used for any important purposes. What if the browser crashes etc.?
If you want to limit to one session per user simply delete/invalidate the old session if a new one is created for some reason.