By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

onbeforeunload : differentiate between different events

rhitam30111985
100+
P: 112
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 :

Expand|Select|Wrap|Line Numbers
  1. var needToConfirm = true;
  2. window.onbeforeunload = confirmExit; 
  3.   function confirmExit()
  4.   {
  5.  // Handle what to do
  6.   }
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
May 13 '09 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
This won't be possible using JavaScript cross-browser. You could perhaps use a hack for it to work partially in one browser, e.g. detect the close 'event' in IE, but that's about it.
May 13 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.