javascript - Cancel default onbefoarunload pop up message inside method -
i have following code, question that, there way can cancel onbeforeunload custom pop inside method call? in case of firefox want show own custom message , if user pressed cancel dont want show default message.
<!doctype html> <html> <head> <script type="text/javascript"> var clicked = false; function copytext() { var span = document.getelementbyid('sp'); if(clicked == false) { clicked = true; span.appendchild( document.createtextnode("clicked") ); } else { clicked = false; span.removechild( span.firstchild ); } } window.onbeforeunload = function () { if(clicked == true) return ; else { if(navigator.useragent.indexof("firefox")!=-1) { if(confirm("are sure want close window without submitting documents?")){ self.close(); return; // want not call custom pop here } } return "are sure want close window without submitting documents?"; } }; //} </script> </head> <!--<body onunload="confirmme()>--> <body> <button onclick="copytext()">click!</button> <br> <span style="color:lightblue" id="sp"></span> </body> </html>
there's no way can cancel onbeforunload event inside function. following show default popup if user doesn't want close page, happens in firefox if user wants stay on page.
window.onbeforeunload = function () { if(clicked == false) { if(navigator.useragent.indexof("firefox")!=-1) { if(confirm("are sure want close window without submitting documents ?")){ self.close(); return; } } return "are sure want close window without submitting documents?"; } };
Comments
Post a Comment