Jump to content
Ezio

Why onunload() does not work ..?

Recommended Posts

Hey guys,

I have a small problem here the onunload event does not work on my firefox...don't know why.

this was the example i tried to run on my browser it's from w3schools

 

<!DOCTYPE html><html><head><script>function goodbye(){alert("Thank you for visiting W3Schools!");}</script></head><body onunload="goodbye()"><h1>Welcome to my Home Page</h1><p>Close this window or press F5 to reload the page.</p></body></html>

 

but it won't work. :-(

Share this post


Link to post
Share on other sites

Have you checked the browser support?

http://www.w3schools.com/jsref/event_onunload.asp

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

Also remember ActiveX Script have to be allowed to this happen (atleast on IE)

Edited by Mudsaf

Share this post


Link to post
Share on other sites

It annoys me when a website has something to say when I want to leave.

I know its annoying but being a noob i need to learn the basics..

Share this post


Link to post
Share on other sites

maybe they were working on a form that required you to store information in a cookie. you could use unload to wipe the cookies to make sure none of the data persists.

 

http://api.jquery.com/unload/

 

This event is available so that scripts can perform cleanup when the user leaves the page.

Share this post


Link to post
Share on other sites

I use unload handlers to run functions on the parent window when a child window is closed.

 

Oh, there's an idea I hadn't thought of.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×