onbeforeunload : differentiate between different events

Discussion in 'Javascript' started by rhitam, May 13, 2009.

  1. rhitam

    rhitam Guest

    Hi all ,

    I was just going through the onneforeunload property here:

    http://www.4guysfromrolla.com/demos/...nloadDemo1.htm


    Now , consider a scenario such as this :

    my website is located at say www.mywebsite.com which has several web
    pages for which i want to have the onneforeunload event . Now , assume
    that all the web pages are including a js file where i can have the
    code for the event which is like this :


    var needToConfirm = true;
    window.onbeforeunload = confirmExit;
    function confirmExit()
    {
    // Handle what to do
    }

    now , the event can fire in either of the following cases:
    1) Tab is closed
    2) User navigates to another page within the same websote.
    3) window is closed
    4) User navigates to another page outside the domain of www.mywebsite.com


    How to handle all these cases separately? To be more specific , how
    can i tell whether the user has navigated within or outside the domain
    of the website?

    Any help appreciated.

    Regards,
    Rhitam
     
    rhitam, May 13, 2009
    #1
    1. Advertising

  2. rhitam

    David Mark Guest

    On May 13, 8:02 am, rhitam <> wrote:
    > Hi all ,
    >
    > I was just going through the onneforeunload property here:
    >
    > http://www.4guysfromrolla.com/demos/...nloadDemo1.htm
    >
    > Now , consider a scenario such as this :
    >
    > my website is located at saywww.mywebsite.comwhich has several web
    > pages for which i want to have the onneforeunload event . Now , assume
    > that all the web pages are including a js file where i can have the
    > code for the event which is like this :
    >
    > var needToConfirm = true;
    > window.onbeforeunload = confirmExit;
    >   function confirmExit()
    >   {
    >  // Handle what to do
    >   }
    >
    > now , the event can fire in either of the following cases:
    > 1) Tab is closed
    > 2) User navigates to another page within the same websote.
    > 3) window is closed
    > 4) User navigates to another page outside the domain ofwww.mywebsite.com
    >
    > How to handle all these cases separately? To be more specific , how
    > can i tell whether the user has navigated within or outside the domain
    > of the website?
    >
    > Any help appreciated.


    You can't do it.
     
    David Mark, May 13, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    13
    Views:
    783
    Richard Tobin
    Aug 11, 2004
  2. Replies:
    5
    Views:
    499
  3. Jo
    Replies:
    7
    Views:
    498
  4. Bob Weiner
    Replies:
    1
    Views:
    126
    Elton W
    May 6, 2005
  5. Replies:
    1
    Views:
    159
    Peter Michaux
    Apr 27, 2007
Loading...

Share This Page