View Full Version : Resolved Leaving Window Warning
bluewalrus
02-11-2009, 08:10 PM
I'm looking for a code that will prompt the user when they are leaving a page similar to gmails when you're in an email and hit backspace, apple(command) w (ctrl w), or click the close window it asks do you really want to leave without sending (or something similar). I have a form on my page want it to do the same thing I don't care if it knows if data was entered or not. Thanks for any ideas you can offer.
rangana created & posted this script (for public use) a few months ago. can't find the thread ATM. the message can be changed to any text you want.
I don't know enough to try, but I suspect it could be modified to pop up when leaving a page instead of just when leaving a domain...? good luck!
<script type="text/javascript">
var domain='http://www.domain.com'; // Set your domain here.
window.onbeforeunload = function()
{
if(this.location.href.indexOf(domain)==-1)
{
return "Are you sure you want to exit?";
}
}
</script>
bluewalrus
02-12-2009, 05:47 AM
OO okay thanks. Yea I figured this would have been posted somewhere before but I also couldn't find it but there are multiple ways of phrasing it so it could be hard to find that way.
let me know if you get it to work when leaving a page vs. leaving a site. I'd be interested in that.
bluewalrus
02-13-2009, 03:04 AM
I think...
<script type="text/javascript">
if(this.location.href.indexOf(domain)==-1)
{
return "Are you sure you want to exit?";
}
</script>
Actually not. hah But leaving the address as not your actually domain will work.
<script type="text/javascript">
var domain='http://www.jkadhkfakshjdfhkashfdjaksf.com'; // Set your domain here.
window.onbeforeunload = function()
{
if(this.location.href.indexOf(domain)==-1)
{
return "Are you sure you want to exit?";
}
}
</script>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.