my onUnload doesnt work

+1 Joan Clarke · August 13, 2015
this is my code

<body onUnload= "alert('YGoodbye');">
igglh';pkjjhxgtxyjugilgbkibkhj
</body>

What am I doing wrong??

Post a Reply

Replies

Oldest  Newest  Rating
+1 Brotsky Tv · September 9, 2015
hey there !

Try like this :

<!DOCTYPE html>
<html>
<body onunload="myFunction()">

<h1>Welcome to my Home Page</h1>

<p>Close this window or press F5 to reload the page.</p>
<p><strong>Note:</strong> Due to different browser settings, this event may not always work as expected.</p>

<script>
function myFunction() {
    alert("Thank you for visiting W3Schools!");
}
</script>

</body>
</html>



For more Javascript tutorial:  https://www.brotsky.tv/category/javascript/
+1 wernich wilsenach · August 14, 2015
seems to be something browsers don't all support properly. for the first time in ages, i found something that worked in IE and not chrome.

change to :


<body onBeforeUnload="alert('YGoodbye')">



and then test it in IE.

not sure what would be a good way to do this which will be browser-independant though. 
  • 1

Javascript

107,013 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators