SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast PainBehindMyEye's Avatar
    Join Date
    Apr 2005
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
    <script language="javascript1.2" type="text/javascript">
    // called if window is closed using 'X' button.
    function SetIt(){
    //Need to store Page for Netscape Look Up
     ThePage=document.location.href;
    }
    function trapIt(){
     
     if(document.all){
     var tempX = event.clientX + document.body.scrollLeft;
     var tempY = event.clientY + document.body.scrollTop;
    //If mouse is over X will return very large negative numbers
      if(tempX<0&&tempY<0){
     
      ItBClosed();
      }
     }
     else{
    //Detects Back/Forward Buttons and Location Box Launching
     ThisPage=document.location.href;
     if(ThePage!=ThisPage){
      //Different Location detected - fine for next and previous
     }
     else{
      ItBClosed();
      }
     }
    }
     
    function ItBClosed(){
     window.open('https://www.sftoolbox.com/bsf.html?SurveyID=136821','popped2','toolbar=no,location=no,status=no,scrollbars=yes,width=500,height=600');
     return false;
    }
    </script>
    <script language="javascript1.2" type="text/javascript">
    // called if graphic 'close' button clicked
    function callMyParentWindow (){
     surveyRequest();
     window.self.blur();
      window.close();
    }
     
    function eventListeners(e) {
     var closeClicked = document.getElementById('UcTop_Container1_subheader_RollOverLink2');
     addEvent(closeClicked, 'click', callMyParentWindow, false);
     //alert('fn eventListeners was called');
    }
     
    
    //addEvent(window, 'load', eventListeners, false);
     
    //function eventListener (e) {
    // var t = window.event ? window.event.srcElement : e ? e.target : null;
    //}
     
    function addEvent (elm, evType, fn, useCapture){
     if (elm.addEventListener){// Check for Gecko event method
      elm.addEventListener(evType, fn, useCapture);
      return true;
     } else if (elm.attachEvent) {// if not above, then check for IE event method
      var r = elm.attachEvent('on' + evType, fn);
      return r;
     } else {
      elm['on' + evType] = fn;
     }
     //alert('fn addEvent was called');
    }
     
    function surveyRequest (){
     window.open('https://www.sftoolbox.com/bsf.html?SurveyID=136821','popped2','toolbar=no,location=no,status=no,scrollbars=yes,width=500,height=600');
     window.self.blur();
    }
    </script>
    Any help is GREATLY appreciated. This one has been driving me bonkers for a long time now.

    - PBME

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast PainBehindMyEye's Avatar
    Join Date
    Apr 2005
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).

    It's almost as if the first function to grab the page isn't working:
    Code:
    function SetIt(){
    //Need to store Page for Netscape Look Up
     ThePage=document.location.href;
    }
    and so later when 'ThePage is referenced, it's seems as if this next section is ignored:
    Code:
    //Detects Back/Forward Buttons and Location Box Launching
     ThisPage=document.location.href;
     if(ThePage!=ThisPage){
      //Different Location detected - fine for next and previous
     }
    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.

    Thanks for you help. All further insight is welcomed.

    - PBME

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PainBehindMyEye View Post
    Which script?
    The one you posted in your first post. It's IE only...

  5. #5
    SitePoint Enthusiast PainBehindMyEye's Avatar
    Join Date
    Apr 2005
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    The one you posted in your first post. It's IE only...
    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.

    Any clues, tips, insight or help is greatly appreciated.

    - PBME

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look into the onbeforeunload event. It is not supported in all browsers though.

  7. #7
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    SitePoint Enthusiast PainBehindMyEye's Avatar
    Join Date
    Apr 2005
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mirek Komárek View Post
    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).

  9. #9
    SitePoint Enthusiast PainBehindMyEye's Avatar
    Join Date
    Apr 2005
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    All help is welcomed and appreciated.

    - PBME

  10. #10
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, I didnt understand, my english is bad. Try to play with this
    opener.document.location.href


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •