如何确定窗口是否在jQuery的回调中关闭unload();方法

问题描述 投票:0回答:1

是否可以找出触发了$(window).unload();的事件的类型?更具体地说,我只对用户关闭窗口(弹出窗口)时的事件感兴趣,而对他仅离开当前页面的情况不感兴趣。

我已经研究了传递给unload();的回调的事件参数,但该对象中似乎没有任何东西,这将是有用的。

有人知道解决方案吗?

代码:

$(function() {
    $(window).unload(function(event) {
        // This is obviously pseudo code. Help me fix it!
        if(event.type == 'closing') { // I had expected something along these lines to work
            // Do stuff before the window closes
        }
    });
});
javascript jquery jquery-events onbeforeunload
1个回答
0
投票

不,据我所知这是不可能的。该文档仅得知它即将被卸载。为什么,这是浏览器的业务。

© www.soinside.com 2019 - 2024. All rights reserved.