Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,345 members, 7,954,401 topics. Date: Friday, 20 September 2024 at 06:11 PM

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

Nairaland Forum / Science/Technology / Webmasters / How To Prevent A Browser Window From Closing (Javacript Only) (1321 Views)

Got A Mail, Dealfish Is Closing Down, Wow! Did They Go Bankrupt By Google Advs. / Pop Up Window Script That Is Multi Browser Supported? / How Can You Prevent A Webpage From Being Saved? (2) (3) (4)

(1) (Reply)

How To Prevent A Browser Window From Closing (Javacript Only) by Nobody: 11:30pm On Feb 13, 2009
<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.

(1) (Reply)

Guys Please Check Out This Amazing Blog. I Think It Is The Best So Far / Contract- Expert In Web-site Builder Needed. / How To Attract Visitors To Your Blog Posts (even When Google Doesn't Help)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.