Results 1 to 5 of 5

Thread: Leaving Window Warning

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Leaving Window Warning

    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.
    Last edited by bluewalrus; 02-12-2009 at 02:36 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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!

    Code:
    <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>

  3. The Following User Says Thank You to traq For This Useful Post:

    bluewalrus (02-12-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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.

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    let me know if you get it to work when leaving a page vs. leaving a site. I'd be interested in that.

  6. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I think...
    Code:
    <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>

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •