Getting confirmation box on browser close

2019-08-15 22:16发布

I have tried below code for mentioned purpose but this is not working in mozila and also i am getting some extra line in confirmation box.

<html>
<head>    
<meta http-equiv="Content-type" content="text/html; charset=utf-8">    <title>Coordinates!</title>
<script type="text/javascript">
 var myclose = false;
 function ConfirmClose()         
 {                 
  if (event.clientY < 0)
   {                         
   event.returnValue = 'Any message you want';
   setTimeout('myclose=false',100);
   myclose=true;                 
}         
}          
function HandleOnClose()         
{                 
if (myclose==true) 
alert("Window is closed");         
} 
</script>


  </head>  <body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()" ><a href="#">test</a> </body></html>

could you please suggest something for mozila.

2条回答
Evening l夕情丶
2楼-- · 2019-08-15 22:47

You can achieve the same using jQuery.

Check this example. Type something in textbox close window.

查看更多
Evening l夕情丶
3楼-- · 2019-08-15 23:04

If you are trying to display a pop up when the user tries to navigate away from the page it is possible and there is even a cross browser solution. But if, what you are trying to do is making a call from javascript to see if firefox is exiting, I dont think that is possible from javascript...then again I might be wrong.

function goodbye(e) {
    if(!e) e = window.event;
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = 'You sure you want to leave?';

    //e.stopPropagation works in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
}
window.onbeforeunload=goodbye;

source

查看更多
登录 后发表回答