如何使用javascript删除卸载事件的提示 [英] How to remove prompt on unload event using javascript

查看:76
本文介绍了如何使用javascript删除卸载事件的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript删除卸载事件的提示?提前谢谢...

How can I remove prompt on unload event using javascript? thanks in advance...

hm,我不想在为身体的unlaod事件触发自定义函数时显示提示...是否可能?所以这是我的代码:

hm, I don't want to show the prompt when firing the custom function for the unlaod event of the body... Is it possible? so here's my code:

window.onbeforeunload = function()
{
    //cancel the unload
            //cancel prompt
}


推荐答案

确保您的事件处理程序中没有 return 语句。从函数返回会触发构造消息。

Make sure your event handler doesn't have a return statement in it. Returning from the function triggers the conformation message.

根据编辑问题中的代码注释进行更新:如果用户做了某些事情离开页面,那么你可以告诉浏览器询问他们是否确定。您无法默默地阻止它们。如果用户希望离开页面,那么他们可以这样做(充满广告和/或恶意软件的狡猾的网站会喜欢它,否则,谢天谢地它不是)

Update based on the code comments in the edited question: If the user does something to leave the page, then you can tell the browser to ask them if they are sure. You cannot silently prevent them. If the user wishes to leave the page, then they can do so (dodgy sites full of adverts and/or malware would love it to be otherwise, thankfully it isn't)

这篇关于如何使用javascript删除卸载事件的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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