This code runs fine on Firefox, but I can't make the unload event work on Chrome anymore. Did Chrome stop supporting the unload event?
This is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript">
function pageHidden(evt) { alert("Are you sure 1?"); } //WORKS ON FIREFOX BUT NOT IN CHROME
window.addEventListener("pagehide", pageHidden, false);
window.onunload = function () { alert("Are you sure 2?"); } //TRIGGERS ON LOAD NOT ON UNLOAD
$(window).unload(function () { //WORKS ON FIREFOX BUT NOT IN CHROME
alert("Are you sure 3?");
});
</script>
</head>
<body>
TEST WEBSITE
<a target='_blank' href="http://www.iamawesome.com">external link</a>
</body>
</html>
How can I get the unload event to work in Chrome?
Thanks!
ANSWER: Don't test the unload event with alerts ;)
Try:
window.onbeforeunload = function () {
// code
};
or
window.onpagehide = function () {
// code
};
You don't trigger anything - you just execute the expression which you want to add as a handler:
window.onunload = function(event) {
alert("Are you sure 2?");
};
Can you help me please to consider where to place resource (service) specific business logic in AngularJS. I feel it should be great to create some model-like abstraction over my resource, but I'm not ...
Can you help me please to consider where to place resource (service) specific business logic in AngularJS. I feel it should be great to create some model-like abstraction over my resource, but I'm not ...
I'm using sinon.js as a way to stub out dependencies in my Mocha tests. I prefer the 'spy' approach over a classic mock approach, as the introspection of the spy seems clearer and affords more ...
I'm using sinon.js as a way to stub out dependencies in my Mocha tests. I prefer the 'spy' approach over a classic mock approach, as the introspection of the spy seems clearer and affords more ...
I get the following error "Web Service method name is not valid" when i try to call webmethod from javascript System.InvalidOperationException: SaveBOAT Web Service method name is not valid. ...
I get the following error "Web Service method name is not valid" when i try to call webmethod from javascript System.InvalidOperationException: SaveBOAT Web Service method name is not valid. ...
I have code like the following: function test(obj) { if(//some conditon) { obj.onload(); }else{ obj.onerror(); } } for(var i=0;i<4;i++){ test({ onload:...
I have code like the following: function test(obj) { if(//some conditon) { obj.onload(); }else{ obj.onerror(); } } for(var i=0;i<4;i++){ test({ onload:...