Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    I've got an application which displays a popup. I need to detect when the user's browser is blocking it, so that I can inform the user why the display he has requested does not appear.

    I found many proposed solutions on the web, all of which boil down to, "save the popup's window object in a Javascript variable, then test the variable to see if it is null or "undefined". Apparently many people have come up with this solution independently.

    For me, it isn't working. Here's a slightly redacted version of my code:

    Code:
    function OpenAPopup(c) {
     var oWin = window.open(c, 'xxx', 'dependent=1,height=680,width=870,menubar=1,toolbar=0,location=0');
     if ( oWin==null || typeof(oWin)=="undefined" ) {
     	alert('A popup blocker is enabled.');
     	return false;
     }
     else
     	return true;
    }
    The window appears very briefly, then disappears again -- the popup blocker at work. The function says, "Window? Sure, boss, window's there all right," presumably before the popup blocker has whacked it.

    This is happening with Internet Explorer 7 under Windows XP.

    I tried adding a delay before testing the object:

    Code:
    function OpenAPopup(c) {
     var oWin = window.open(c, 'xxx', 'dependent=1,height=680,width=870,menubar=1,toolbar=0,location=0');
     var date = new Date();
     // Delay one second.
     var curDate = null;
     do { curDate = new Date(); }
     while (curDate-date<1000);
     // Now, is the window still there?
     if ( oWin==null || typeof(oWin)=="undefined" ) {
     	alert('A popup blocker is enabled.');
     	return false;
     }
     else
     return true;
    }
    It doesn't help. The browser creates the window, waits one second, paints the window, then removes it. Again, the function doesn't know that anything has happened.

    What's wrong here? The technique apparently works for other people; why isn't it working for me?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Can you make the popup window's object variable global and use window.setTimeout(function,1000) to test for it? Does it help?

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    It seems not. In my test, the popup appears briefly, then disappears. A second later the timeout function executes and reports that the popup is still there.

    I'm working somewhat beyond my range of Javascript experience here, so I may have made an obvious error (or a subtle one) that prevents my code from working although the technique itself is viable. Here's what I did:

    Code:
    // global variable used by OpenCert and PopupTest.
    var goWin;
    
    function OpenPopup(c) {
     window.setTimeout('popupTest()',1000);
    	goWin = window.open(c, 'xxx', 'dependent=1,height=680,width=870,menubar=1,toolbar=0,location=0');
    	return true;
    }
    
    function popupTest() {
    	if ( typeof(goWin)=="undefined" ) {
     alert('A popup blocker is enabled.');
    	}
    	else {
     alert('No popup blocker is enabled.');
    	}
    }

  4. #4
    5 Star Lounger RussB's Avatar
    Join Date
    Dec 2009
    Location
    Grand Rapids, Michigan
    Posts
    803
    Thanks
    10
    Thanked 50 Times in 49 Posts
    No offense intended, but when I encounter a pop-up that gets by my blocker I seek an update for my blocker or another blocker.
    When working on sites where I know that pop-ups are used and that I want/need I simply turn the blocker off for the page or domain, is this not an option?
    Do you "Believe"? Do you vote? Please Read:
    LEARN something today so you can TEACH something tomorrow.
    DETAIL in your question promotes DETAIL in my answer.
    Dominus Vobiscum <))>(

  5. #5
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,168
    Thanks
    47
    Thanked 978 Times in 908 Posts
    Have you tried cascading style sheets to overlay a form for the required data?

    cheers, Paul

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    Code:
    function popupTest() {
    	if ( typeof(goWin)=="undefined" ) {
     alert('A popup blocker is enabled.');
    	}
    	else {
     alert('No popup blocker is enabled.');
    	}
    }
    The problem may be that the variable is "defined" but its value is null. I'd need to drag out a JavaScript book to figure out how best to test whether the window exists.

  7. #7
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    jscher2000 wrote, "The problem may be that the variable is "defined" but its value is null."

    I didn't think so, but since you suggested it, I tried it. Unfortunately it didn't help.

    P T wrote, "Have you tried cascading style sheets to overlay a form for the required data?"

    The object here is to fix a nagging problem with a web site that is approaching its end of life. Design changes are not on the agenda; they would just delay the development of the new site.

    When the new site is implemented, it will eliminate the problem by writing what's currently in the popup to a PDF and letting the customer download it. (The customer generally wants to print and keep the content, so a PDF is a superior vehicle in any case.)

    RussB wrote, "No offense intended, but... When working on sites where I know that pop-ups are used and that I want/need I simply turn the blocker off for the page or domain, is this not an option?"

    No offense taken, but you're looking at the problem the wrong way around. It's not a problem with "my blocker," but with my client's customers, who tend not to be very tech-savvy, and frequently don't even know what a popup blocker is. By the time a customer calls us because he can't get at the information in the popup we've already lost a great deal of goodwill, and then we have to spend a substantial amount of time talking him through one or another workaround. That's not a solution to the problem; that is the problem.

  8. #8
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,168
    Thanks
    47
    Thanked 978 Times in 908 Posts
    As you need to work around the lack of a pop up, why not just have the page show in the current browser with a big Back button and a Print button? Then it works for everyone.

    cheers, Paul

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Waiting 2 seconds and checking for a document object in the new window yields this code that works in a "manual" test (closing the popup using Ctrl+w).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <script type="text/javascript">
    var goWin;
    function OpenAPopup(c) {
      goWin = window.open(c, 'xxx', 'dependent=1,height=680,width=870,menubar=1,toolbar=0,location=0');
      window.setTimeout('popupTest()',2000);
    }
    function popupTest() {
      // Now, is the window still there?
      if ( goWin==null || typeof(goWin)=="undefined" ) {
        var noWin = (goWin==null ? 'goWin==null' : 'goWin!=null');
        var tWin = (typeof(goWin)=="undefined" ? 'typeof(goWin)==undefined' : 'typeof(goWin)!=undefined');
        alert('A popup blocker is enabled.\n'+ noWin + '\n' + tWin);
        return false;
      }
      else {
        try {
          var oDocNew = goWin.document;
          if (oDocNew==null) {
            alert('A popup blocker is enabled.\ngoWin.document==null');
            return false;
          }
          else alert('OK');
        } 
        catch(e) {
          alert('A popup blocker is enabled.');
        }
      }
    }
    </script>
    </head>
    <body onLoad="OpenAPopup('about:blank')">
    
    
    This is a test.</p>
    </body>
    </html>

  10. #10
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    I had to move on before I had a chance to try the last suggestion. I just got a chance to try it, with puzzling results.

    In Firefox 3, it works. That's progress. In IE7 and IE8 (on two different machines) it doesn't work -- not because it fails to report when the popup blocker does its thing, but because the popup blocker never does its thing, not matter how the options are set.

    Right now I'm testing in IE8 with the following settings. These apply to the local intranet zone, which is where I'm testing.

    Security page: setting is "medium-high."

    Privacy page: setting is "medium". "Turn on Pop-up Blocker" is checked. Pop-up blocker "settings" defines only one allowed site (not localhost). "Play a sound" is checked. "Show Information Bar" is checked. Blocking level is set to "High: Block all pop-ups."

    Does anyone have an idea about what is happening?

Posting Permissions

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