JavaScript popup on window close: works great on IE, works terribly on FF!!! - Help!

The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

JavaScript popup on window close: works great on IE, works terribly on FF!!! - Help!

I'm just restating my "site abandonment" post but with a clearer title as I realized it probably only made sense to me and me alone.

I have window that pops up with our commerce system. I have it set to pop up a window via JavaScript if the visitor quits early in the process (abandons the commerce system before completing all of the steps. The new popup is just a customer survey ("why are you leaving, is there something else we can help you with" etc. etc.).

Here's the problem, it works fine in IE, but in Firefox, anytime the page in the original commerce window is changed, refreshed or advanced to a new page, the survey popup window is called rather than just on window close.

Again, here's the two JavaScript routines that handle clicks on the graphical close button and on the window 'X' close button.

The script you are using seems to be ancient. Skip the document.all check and also get rid of the language="JavaScript 1.2" attribute, its deprecated since years and might even hinder the script to be run at all.

Which script? Certainly the first one is a little old but it is the one being called anytime the 'X' button is pressed and shouldn't instance a new window on page change (function trapIt()).

The second script I wouldn't exactly agree with you in saying it's 'ancient'. Yes I did use the old Language= statement but I do have to cater to a varied audience (our site traffic reporting proves this) so I decided to err on the side of caution (I'm not exactly sure what will happen with older browsers).

The whole point to this last bit is to make sure it doesn't fire when the page changes rather than when the window closes but it happens anyway.

The second script is just an event listener to "hear" if the graphic-based close button image has been clicked so it won't fire on a page change as opposed to a window close. I don't think attaching event listeners like this is 'ancient', do you?

So, that said, again is there some issue in this first script that jumps out as being the problem? I'll try dropping the document.all 'if ' statement and just declare the vars, I'll also drop the 'language=' attribute to see if these two make any difference.

How would you suggest I test for a window closing in FF? I can't come up with a way that works in FF if the user clicks the 'X' button of the window while also not having FF treat changing pages as the same as the window closing.

If I understand what would you like to do, I have to say thanks god, that I dont have to use browser in which this works. You really want to make a popup window, which is not possible to close? I think people love to press ctrl+alt+del to switch off browser, or I understand something in your first post wrong? Maybe you can download this code to see why are such things not allowed in modern browsers http://jeff.czweb.org/javascript/3_s...d.php?get=nerv
But when you decompress it see the code at first, than save all your work, because you will have restart computer probably. So that is why this not workink and some antivirus program call this an virus, because it is not possible to close. In true this not a virus it is just stupid joke. Another such script you can find here http://www.codelifter.com/main/javas...fromhell1.html also IE only.

If I understand what would you like to do, I have to say thanks god, that I dont have to use browser in which this works. You really want to make a popup window, which is not possible to close? I think people love to press ctrl+alt+del to switch off browser, or I understand something in your first post wrong? Maybe you can download this code to see why are such things not allowed in modern browsers http://jeff.czweb.org/javascript/3_s...d.php?get=nerv
But when you decompress it see the code at first, than save all your work, because you will have restart computer probably. So that is why this not workink and some antivirus program call this an virus, because it is not possible to close. In true this not a virus it is just stupid joke. Another such script you can find here http://www.codelifter.com/main/javas...fromhell1.html also IE only.

No, I'm not trying to create a window that the user cannot close. I'm trying to listen to see if the window has been closed either with the window's 'X' button or with another image on the page (a "button" image to close the window). I want to listen for the window close and fire off a function as it closes. The reason? I'm opening an exiting survey in another window to ask the user why they are leaving and if they found what they were looking for (this is within a commerce engine where people are getting price quotes and/or buying something).

Can anybody see why this works perfectly in IE but fails to work properly in FF? FF pops open the new window anytime the page is refreshed or if a link to another page is clicked. This is NOT supposed to happen. The document.all test is supposed to fail so that the check ThePage!=ThisPage allows FF to ignore a page change and only watch for the window close.

Is there a way to reliably and cross browser compatible, call a function when a window is closed that is not also called when the document within the window changes?

Removing document.all and the language attribute had no effect at all. The only change was that by removing document.all, it no longer worked in IE (???).

I've gone around this one so many times now, I simply cannot find a way to make this work in FF properly.