【问题标题】:onbeforeunload works also with refreshingonbeforeunload 也适用于刷新
【发布时间】:2013-03-16 15:36:11
【问题描述】:

我几天前提出了这个问题 (Java session deleted after page refresh),但没有得到答案。可能是因为问题出在 onbeforeunload 事件中。 与:

 <body onbeforeunload="chiudi()">

我想对会话进行突击检查。问题是这样会话将是
如果用户刷新页面,也会被触发。我该如何解决?

这是我的 javascript 函数 chiudi()

 function chiudi(){
 var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST", "SvuotaSession", false);
    xmlHttp.setRequestHeader("Content-type",
            "application/x-www-form-urlencoded");
    xmlHttp.send(null);
 }

【问题讨论】:

    标签: javascript ajax refresh onbeforeunload page-refresh


    【解决方案1】:

    我不认为你可以。不允许您获取有关用户要去哪里的信息(根据this),因此无法知道用户正在刷新当前页面。

    【讨论】:

    • :-( 如果用户关闭页面,会话是否会自动进行?
    • 如果“步枪”是指会话结束,这取决于服务器端技术。 ASP.NET 最终会根据超时结束会话。不确定您使用的是什么服务器端技术。
    猜你喜欢
    • 2012-06-10
    • 2014-12-22
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2014-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多