Search code examples
htmlonunload

onunload doesn't work when page is closing, for safari


<body onunload="notReady()">
<script >
    function notReady(){
      alert("closing")
    }
</script>
</body>

it works only when refreshing the page or clink some link on the page and the page is actually unloading, but not when it's closing.

why ? and how to make it work?


Solution

  • It should be work,

    window.onbeforeunload = function() {
        return "closing!";
    };