在JS中杀掉卸载功能? [英] Kill unload function in JS?

查看:85
本文介绍了在JS中杀掉卸载功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用javascript(jquery)杀掉卸载函数?

Is there a way to kill the unload function with javascript(jquery)?

我正在寻找这样的东西:

I am looking for something like this:

window.onbeforeunload = function(){
    confirm("Close?")
}

或在jquery中:

$(window).unload(function() {
    confirm("close?")
});

现在,在窗口卸载时,我收到确认提醒,但无论如何都会继续。点击取消它将不会停留在我的页面上。

Now, on window unload I get my confirm alert but it will continue in any case. Clicking cancel it won't stay on my page.

推荐答案

该函数必须返回 false 要中止或 true 要继续,所以你只需返回这样的确认:

the function has to return false to abort or true to continue, so you cauld simply return the confirm like this:

window.onbeforeunload = function(){
   return confirm("Close?")
}

这篇关于在JS中杀掉卸载功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆