如何使用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)