调用卸载前事件



我的应用程序中有一个dhtmlx窗口。当用户进行更改,然后按下Backspace时,我希望显示以下对话框:

https://cube3x.com/wp-content/uploads/2014/02/confirm-navigation.png

这是加载dhtmlx窗口的代码:

var win = dhxWins.createWindow("selectIt", 10, 10, 940, 550);
        win.setText(some_text);
        win.denyResize();
        win.denyPark();
        win.setModal(true);
        win.center();
        win.attachURL("/sdgdsggh/SelectIt");
        win.attachEvent("onClose", function (win) {
            return true;
        });
//This is what I tried
        win.attachEvent("beforeunload", function (win) {
            debugger;
            return true;
        });

我知道我应该调用卸载前事件,但我该怎么做?

您不需要调用beforeunload,当您的窗口卸载时,浏览器会自动触发该事件

您可以在窗口对象上使用addEventListener。

**

window.addEventListener('beforeunload',
            function(){console.log(unloaded)});

**

最新更新