如何使用 javascript 删除卸载事件上的提示
如何使用 JavaScript 删除卸载事件的提示?预先感谢...
嗯,我不想在为 body 的 unlaod 事件触发自定义函数时显示提示...可能吗?所以这是我的代码:
window.onbeforeunload = function()
{
//cancel the unload
//cancel prompt
}
How can I remove prompt on unload event using javascript? thanks in advance...
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的事件处理程序中没有
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)
绝对不是不可能。要抑制提示,您所要做的就是省略“return”语句。返回任何值都会导致触发提示。例子:
Most certainly NOT impossible. All you have to do to suppress the prompt is omit the "return" statement. Returning any value will cause the prompt to fire. Example: