Can you help me with this problem . I am using Modzilla Firefox in Linux . When I close the window or reload the page the onunload event sees not work
<html>
<head>
<title>onunload test</title>
<script type="text/javascript">
window.onunload = unloadPage;
function unloadPage()
{
alert("unload event detected!");
}
</script>
</head>
<body>
<p>Reload a new page into the browser<br />
to fire the unload event for this page.</p>
<p>You can also use the back or forward buttons<br />
to load a new page and fire this event.</p>
</body>
Try this code snippet :
window.onbeforeunload = function(){
return 'Are you sure you want to leave?'; // or anything you want to do
};
try to use jQuery libraries, because jquery consider different kinds of browser i think :)
$( window ).unload(function() {
alert( "unload event detected!" );
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.