onbeforeunload : differentiate between different events

R

rhitam

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
 
D

David Mark

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top