http://www.perlmonks.org?node_id=273090

I was helping a friend with his Tripod* site a few days ago, and soon I was very annoyed by the multitude of popup windows. I suggested he install Mozilla, but he didn't want to install such a big package for one day. Then I suggested he install the Google toolbar, but he balked at that too. Finally, I suggested I create a quick popup blocker with Perl, which was already installed, and he said "Fine!" with a touch of irritation in his voice.

So I did, and just a few minutes later, here's the result:

#!perl use strict; use warnings; use Win32::OLE qw/EVENTS/; use Win32::OLE::Variant; my $ie = Win32::OLE->CreateObject('InternetExplorer.Application', 'Qui +t') or die "Can't start IE", Win32::OLE::LastError(); $ie->{Visible} = 1; $|++; Win32::OLE->WithEvents($ie, 'main', 'DWebBrowserEvents2'); $ie->GoHome; Win32::OLE->MessageLoop(); sub NewWindow2 { my ($self, $browser, $cancel) = @_; $cancel->Put(1); print "$self->{LocationURL} tried to open a new window!\n"; } sub OnQuit { Win32::OLE->QuitMessageLoop; }

Okay, it has some features (read limitations ;). It will block all new windows (even when you use the "Open in New Window" context menu) and it only works on the instance of IE that it started.

* Note - Tripod upgraded to 5.8 :) - but without any core modules :(

Replies are listed 'Best First'.
Re: Popup blocker for IE
by ajdelore (Pilgrim) on Jul 11, 2003 at 19:17 UTC

    I browse the web with just about everything in IE 6.0 shut down: ActiveX, Javascript, Java, cookies, re-directs, animated gifs, plug-ins, mixed content, etc....

    This works fine, and gets rid of a ton of annoying ads on the web. Of course, a lot of sites don't work, or don't work properly, but that is just bad design.

    For sites that I want to use, I just add them to the trusted sites list with a different set of parameters. On-line banking and stuff like that works fine.

    </ajdelore>

Re: Popup blocker for IE
by smalhotra (Scribe) on Jul 11, 2003 at 16:18 UTC
    Neat, but it only works if I use the 'Shift-Click' method of opening new windows. Maybe I should read the ole' OLE docs.
    PS. Activestate perl 5.8.0, win.2k.sp3, ie6.0.2800

    $will->code for @food or $$;

      Hmmm... interesting. Tested on three computers: XP/IE 6 Perl 5.8 (friend), Win2K sp3 IE 5.5 (home), and Win2K sp3 IE 6 (work). It worked as advertised on all three.

      According to MSDN, the NewWindow2 event is fired before every new window opened. Are you sure you're using the IE window opened by the script? It will print the URL of every site that tries to open a new window and the script should stop when you close that window.

      Anyway, it was useful for it's purpose. I use Mozilla as my everyday browser, so I never see an unwanted popup.

Re: Popup blocker for IE
by maksl (Pilgrim) on Jul 12, 2003 at 10:16 UTC
    your friend better update to mozilla, their pop-up blocker is fine-grained and well trained :)
    101 things that the Mozilla browser can do that IE cannot was compiled against moz 1.2. now we have moz 1.4 and it's even more stabler :)
    as a side note: woody debian user (like me) can add this to their /etc/apt/sources.list:
    # newest moz backport to woody deb http://debian.relativ.org/ ./
    it's the quickest backport from sid
Re: Popup blocker for IE
by puff (Beadle) on Nov 28, 2005 at 23:56 UTC
    Tested under XP IE 6 SP 2 against http://www.popuptest.com/popuptest12.html.
    It fails to block pupups. I suspect there are now changes in Win32::OLE that have changed the behavior.

    More ...................

    It turns out there is a bug in Win32::OLE. Jan Dubois has provided a patch and I expect that this will work OK going forward.
Re: Popup blocker for IE
by John M. Dlugosz (Monsignor) on Jul 11, 2003 at 16:14 UTC
    Interesting that he was more annoyed at "doing something" than at the popups. I guess that's the mentality of most users, and why they continue to exist?

    I use Guidescope, and that blocks the ads that would have generated popups.