473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

onbeforeunload : differentiate between different events

rhitam30111985
112 100+
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
1 1534
acoder
16,027 Expert Mod 8TB
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

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

Similar topics

2
by: Robert Oschler | last post by:
I have a web page where I want to make sure that an image HTTP request is successfully made before the page unloads. The request is made by setting the image element's SRC property to the desired...
1
by: Robert Oschler | last post by:
I've successfully attached to the "onclick" and several other events using AttachEvent(). But when I try to attach to the "onbeforeunload" event it doesn't work (the handler I've assigned is never...
1
by: rufus | last post by:
I have a function that checks whether the user is trying to navigate away from the page before saving all their data. I achieve this using the window.onbeforeunload javascript event. It fires...
5
by: Eric Robishaw | last post by:
If I want to show a closing message ONLY if the user is trying to close the browser, I need to determine the cause of onbeforeunload being called. The following attempts do NOT work: checking...
4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
6
by: Marcia Gulesian | last post by:
What code can I put in the 'onbeforeunload' event to cancel the 'unload' action (when user closes browser) and then present the user with an alert saying that he/she must use the logout button.
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
5
by: allan.young | last post by:
Hi, When in gmail I'm composing a new email message and I bit the browser back button, I get a dialog that says "Your message has not been sent. Discard your message?" But if instead of...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.