Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Pop-ups 2

Status
Not open for further replies.
Joined
Oct 15, 2003
Messages
145
Location
US
is there a way to detect if a person has a pop-up blocker on - like there is a way to detect if they have cookies enabled - navigator.cookieEnabled ?
 
I keep forgetting to look for it, I'll leave myself a note right now... (writing note) ...

I think the problem was caused in IE with Google toolbar popup blocker. It returned something that was non-null, but not a window handle. Unfortunately I couldn't just test for type 'window' because for some reason that caused Firefox to choke.

Honest, I'll look for it tonight and get back to you.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tracy - I would like to know as well! Thank you in advance for taking the time to look it up!
 
[red]I remembered![/red]

Here is the code I came up with to check for popups:
Code:
function checkPopups() {
  // Pop up a small test window, see if it exists, then close it
  wTest = window.open('./testPopup.html','testWin','width=20,height=20,resizeable=no,scrollbars=no');
  // IE 6.0 dies on "instanceof Window" and Mozilla will
  // return an object even if popups are disabled, so
  // check that an object is returned AND that it has
  // several common properties of a window.
  // This still doesn't work in Navigator 4.x - too bad.
  if ( wTest == null ||
       wTest.frames == null ||
       wTest.document == null ||
       wTest.opener == null ||
       wTest.screen == null ||
       wTest.history == null ||
       wTest.navigator == null ) {
    return false;
  }
  wTest.close();
  return true;
}
Note that I had the situations backwards. Mozilla (FireFox) was returning an object even with popups disabled, and IE died (and I do mean died!) when I used "instanceof window" to test it (that worked in FF).
So I came up with this code to make sure the object returned wasn't a window. To be certain, I just took the DOM from both IE and FF and checked for every major attribute of a window object that they BOTH had in common.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Great code tsdragon!

__________________________________________
Try forum1391 for lively discussions
 
Thanks. If you take out all the comments it's also pretty short. However I'm glad now I took the time to type them all in and leave them there. Otherwise I'd have no idea what the problem originally was.

A lesson for the new coders out there (and a reminder for the "pros")!


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tracy,

Using the same browser conditions you used to test your code with, can you test my code here, please?


I just cannot get it to break under IE or FF, and all I'm doing is this when the windows loads:

Code:
var winHandle = window.open('[URL unfurl="true"]http://www.google.co.uk/',[/URL] '', '');
if (winHandle == null) alert('Popup was blocked');

Thanks,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
Dan,

I'd like to be able to accomodate you, but just this past weekend I upgraded my home system from Win98 to WinXP, so I don't have the same environment any more. I haven't even gotten around to loading FF on it yet (I only have a 56K connection and I haven't had time to download it).

I did try it just now at work with the IE-engine-based FlashPeak SlimBrowser v4.04 build 003. With popup blocking off I get a new tab (window) opened. With popup blocking on I get nothing (no new tab/window, no alert). All I see is the "block popups" toolbar button flash to indicate that it blocked a popup.

I think the problem has to do with how the particular browser handles blocking. Some apparently "fake out" the page attempting the popup by passing back a bogus window handle.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top