I have tried below code for mentioned purpose but this is not working in Mozilla 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(&q开发者_如何转开发uot;Window is closed");
}
</script>
</head> <body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()" ><a href="#">test</a> </body></html>
Could you please suggest something for Mozilla?
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
You can achieve the same using jQuery.
Check this example. Type something in textbox close window.
精彩评论