admin管理员组文章数量:1325236
As per how StackOverflow does it when you are adding a question or replying to a question;
I'd like to prompt the user with a;
"Are you sure you want to navigate away from this page"
"Press OK to continue or Cancel to stay on this page"
I've tried a couple of js snippets i've found on ze internet, but nothing quite cuts the mustard.
As per how StackOverflow does it when you are adding a question or replying to a question;
I'd like to prompt the user with a;
"Are you sure you want to navigate away from this page"
"Press OK to continue or Cancel to stay on this page"
I've tried a couple of js snippets i've found on ze internet, but nothing quite cuts the mustard.
Share Improve this question asked Apr 14, 2010 at 15:59 GordonByGordonBy 3,4076 gold badges33 silver badges53 bronze badges 2- 4 More detail on the mustard please. – D'Arcy Rittich Commented Apr 14, 2010 at 16:02
- 1 possible duplicate of stackoverflow./questions/1289234/… – Peter Bailey Commented Apr 14, 2010 at 16:06
1 Answer
Reset to default 7You need to implement window.onbeforeunload and return your message from it as a string:
window.onbeforeunload = function() {
if (theUserHasStartedEditing) {
return "You have started writing or editing a post."
}
}
There's an online demo here: https://web.archive/web/20210619174356/https://www.4guysfromrolla./demos/OnBeforeUnloadDemo2.htm
本文标签: javascriptPrompting and preventing user from navigating awayclosing a pageStack Overflow
版权声明:本文标题:javascript - Prompting and preventing user from navigating awayclosing a page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742168158a2426213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论