Ezio Posted September 3, 2013 Share Posted September 3, 2013 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. :-( Link to comment Share on other sites More sharing options...
Mudsaf Posted September 3, 2013 Share Posted September 3, 2013 (edited) 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 September 3, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
Ezio Posted September 3, 2013 Author Share Posted September 3, 2013 yes i have checked and it says it is supported in firefox right.? then why won't it work?? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 3, 2013 Share Posted September 3, 2013 Your right it does not work, But! window.onunload = window.onbeforeunload = (function(){myFunction()}) seems to Link to comment Share on other sites More sharing options...
davej Posted September 3, 2013 Share Posted September 3, 2013 It annoys me when a website has something to say when I want to leave. Link to comment Share on other sites More sharing options...
Ezio Posted September 4, 2013 Author Share Posted September 4, 2013 (edited) Thanks dsonesuk it works, but why doesnot the onunload function work..?? Edited September 4, 2013 by Ezio Link to comment Share on other sites More sharing options...
Ezio Posted September 4, 2013 Author Share Posted September 4, 2013 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.. Link to comment Share on other sites More sharing options...
davej Posted September 4, 2013 Share Posted September 4, 2013 When would this event be useful? Link to comment Share on other sites More sharing options...
thescientist Posted September 4, 2013 Share Posted September 4, 2013 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 4, 2013 Share Posted September 4, 2013 I use unload handlers to run functions on the parent window when a child window is closed. Link to comment Share on other sites More sharing options...
davej Posted September 4, 2013 Share Posted September 4, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now