JavaScript I can't trigger the unload event in Chrome canvas,canada,canada goose,cane corso,cancelled,canes,candace parker,

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 ;)

Answer:1

Try:

window.onbeforeunload = function () {
    // code
};

or

window.onpagehide = function () {
    // code
};
Answer:2

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?");
};
Answer:3

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. ...

  1. service method name is not valid
  2. web service method name is not valid
  3. web service method name is not valid. c#
  4. web service method name is not valid asmx
  5. web service method name is not valid vb.net
  6. web service method name is not valid json
  7. web service method name is not valid ajax
  8. web service method name is not valid. jquery asmx
  9. $metadata web service method name is not valid
  10. soap web service method name is not valid
  11. postman web service method name is not valid
  12. soaphttpclientprotocol webservice 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:...