Saumil
Saumil

Reputation: 2517

How to use onload and onunload in a same javascript program?

My code is:-

<html>
<head>
    <script>
        function welcome()
        {
            alert("Successfully loaded");
        }
        function bye()
        {
            alert("Unload");
        }
    </script>
</head>
<body onload="welcome()" onunload="bye()">

</body>

when i execute this only the function for "onload()" is called. Can you tell me how to trigger "onunload()" event also...

Upvotes: 0

Views: 1718

Answers (1)

Netorica
Netorica

Reputation: 19327

It really depends on what browser you test it

The onunload event is supported in IE, Firefox, and Safari, but not supported properly in Chrome or Opera.

please try onbeforeunload

<body onload="welcome()" onbeforeunload="bye()">

</body>

https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload

Upvotes: 1

Related Questions