Advanced Search

Results 1 to 4 of 4

Thread: Message on page exit...

  1. #1
    Join Date
    Apr 2008
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Message on page exit...

    All I want is a simple message to appear on the page exit - just to say goodbye etc. I'm sure I've done this before, but couldn't find it anywhere! The closest I got was this script from Javascriptkit: http://www.javascriptkit.com/script/...alertmsg.shtml - except that this displays the message on loading the page, not leaving. If anyone can help that would be great... still learning the basics of Javascript, so haven't had much luck understanding what is going on that code so far...

    Thanks in advance

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Code:
    <script type="text/javascript">
      window.onbeforeunload = function()
      {return "Are you sure you want to exit?";}
    </script>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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

    rhiaro (06-09-2008)

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

    Default

    cool. could that be modified to show the message only when leaving the domain (and not when leaving the page for another on the same site)?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  5. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Quote Originally Posted by traq View Post
    cool. could that be modified to show the message only when leaving the domain (and not when leaving the page for another on the same site)?
    See if this helps:
    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>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •