View Full Version : How to create an error message when one closes the window

05-04-2011, 08:56 AM
I would like to know how to create an error message when someone decides to close my blog!
For example i am on your blog and you don't want me to go from your blog. So. inorder to make the person to think twice you will create an error message when someone closes your window with the message that you will be providing an better offer!!

Iam a complete beginner in this!!

Any Help will be appreciated!!

Thanks in advance!!

05-04-2011, 12:36 PM
I'd rather you didn't - just make your blog more interesting! (If I received this error message I would never come back!)

<body onbeforeunload="alert('Goodbye forever!');" >

05-04-2011, 03:03 PM
Andrew..."onbeforeunload" will work good on all browsers ? Long back I had some problem with Firefox and fixed by a friend.

05-04-2011, 03:13 PM
uggghhh. Nothing I hate worse than trying to leave a site and a message pops up asking me am I sure I want to leave. Well if I clicked the "X" then YES I'm wanting to leave!

As Kor said, dont make your visiters annoyed and risk them never coming back just to add some fancy javascript like this. I dont usually go back to sites like this either.

05-04-2011, 03:40 PM
If you still insist on doing this :mad: then it works.. as well as can be expected! But not properly in Opera.