Web Analytics Made Easy -
StatCounter Navigating away from a page - CodingForum

Announcement

Collapse
No announcement yet.

Navigating away from a page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Navigating away from a page

    Does anyone know how to check when a user navigates away from a certain page? Like clicking on a link, or even just closing the browser window. Is there a way to check for this using javascript?

  • #2
    onunload

    <body onunload="alert('Bye bye!')">
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Incredible. Thanks.

      Comment


      • #4
        Welcome.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Do you know how to cause the popup to have the "OK" or "Cancel" buttons, so that the user can stop the new page from loading? meebo.com uses this to warn the users that they are leaving the meebo page, and the users can stop the action.

          Comment


          • #6
            <body onLoad="prompt('Do you wish to continue?');">

            Comment


            • #7
              Bear in mind that the alert/prompt will not differentiate between internal and external links. i.e. It will also be triggered even if the user is navigating to another part of your site.


              Originally posted by markhartnady
              <body onLoad="prompt('Do you wish to continue?');">
              This is presumably useless for alerting/prompting users who leave a page as it needs to reside on the destination page - which, if it's another site, isn't going to be the case.
              Additionally, using a prompt onload is doubly useless as you're really only asking if the user wishes to use the page which has just loaded. Either way, the page has already loaded and the browser won't return them to the previous page even if they decline the prompt.
              Last edited by Bill Posters; Apr 19, 2006, 05:38 AM.
              Why you should validate your code before asking for help...

              Comment

              Working...
              X