How To Prevent A Browser Window From Closing (Javacript Only)

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 23, 2009, 08:22 AM
431091 members and 298155 Topics
Latest Member: touisneun
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: OmniPotens, yawa-ti-de)  |  How To Prevent A Browser Window From Closing (Javacript Only)
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: How To Prevent A Browser Window From Closing (Javacript Only)  (Read 78 views)
*dhtml
How To Prevent A Browser Window From Closing (Javacript Only)
« on: February 13, 2009, 11:30 PM »

Quote
<script type="text/javascript">
var domain='http://www.mwebng.net'; // Set your domain here.
window.onbeforeunload = function()
{
if(this.location.href.indexOf(domain)==-1)
{
return "Are you sure you want to exit?";
}
}
</script>

Demo Link: http://www.mwebng.net/demos/leave


This is a very simple way to prevent a browser window from closing. Facebook and some other self-respecting websites make use of this kind of technique to prevent the browser window from closing, if say you fill a form and did not save it before attempting to leave the browser window.


* leave.gif (25.49 KB, 953x567 )
 At Our Taxes We Have To Dig A Tomb  Microsoft Window Xp And Window Vista Running Simultaneously On Your Laptop:   It Is For Any Www.nairaland.com Members!  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.