Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,135,563 members, 7,751,710 topics. Date: Thursday, 29 February 2024 at 09:34 AM

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) (1286 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)

Graphic And Web Design Association Of Nigeria (gwan) / Just Joined This Forum :) / Nigeria Bloggers Conference

(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. 5
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.