MSDN Magazine > Issues and Downloads > 2002 > April >  Editor's Note: Pop-up Stopper Stops Pop-ups in ...
From the April 2002 issue of MSDN Magazine
MSDN Magazine
Pop-up Stopper Stops Pop-ups in their Tracks
Download the code for this article: WatchIE.exe (50KB)

This month we'd like to complain about pop-under ads. You know what they are. You're surfing along happily, when suddenly you get instant spam—an ad for a 19.9 percent unsecured Visa card from Fourth National Bank of The Seychelles. Sometimes there will be four or five of them just waiting for you to finish checking the local weather forecast. Then—whumpf!—you're spending the next 20 minutes closing the windows. (Except when you're using Windows XP and you've grouped similar taskbar buttons. Then you can close their icons without looking at the ads.)
      It wasn't long before marketers realized that people didn't like these ads crammed down their throats because they actually take more effort to ignore than banner ads. So, not satisfied with having developed the perfect ad campaign—intrusive, unwelcome, and product-adverse—they've gone two steps farther now.
      The first is the full-page animated ad, which has gotten quite a few sites personally blacklisted. Let's say you're checking the weather. All of a sudden, some ghastly sprite starts animating itself across the screen. Maybe it's falling leaves or something related to the advertiser's embedded ad. And all you want to do is click the address field and get out of there, but you can't because somehow the focus keeps going to those g#*#(@! falling leaves and when you click, you go to the Falling Leaves site. And then they get to count it as a click!
      If that's not bad enough, Wired News recently reported on a new breed of Web software called "scumware," installed as ride-alongs to other products. They run in the background, and when you go to a search page and type in "halitosis," they pop up a page that sells mouthwash. So a Web site doesn't even have to know that it's spawning pop-ups anymore—this Trojan program does it for its creator's own business partners.
      What's the solution? We've figured out how to fix at least some of this—the pop-up ad problem. It would be great if Microsoft Internet Explorer had an "accept/reject pop-up" setting like it does for cookies. Since it doesn't, we've been working on our own substitute. It's a simple concept—instead of launching Internet Explorer directly, you can run a program that launches it indirectly:

Dim WithEvents IE As InternetExplorer

Private Sub StartIE
    Set IE = CreateObject("InternetExplorer.Application.1")
    IE.Visible = True
End Sub
You have to create the Internet Explorer object with the WithEvents keyword, which lets you hook its events in your code. Next, you can hook this object's NewWindow2 event:
Private Sub IE_NewWindow2(ppDisp As Object, Cancel As Boolean)

Set IEx = CreateObject("InternetExplorer.Application.1")

   Set ppDisp = IEx
   IEx.Visible = False

End Sub
The program creates a second pop-up window, but doesn't make it visible yet. Since the window is created first, then receives navigation instructions, you can hook this object's BeforeNavigate2 event to determine whether the requested URL is on a list of banned URLs or whether the user wants to add it to one.
Private Sub IEx_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, _
  Flags As Variant, TargetFrameName As Variant, PostData As Variant, _ 
  Headers As Variant, Cancel As Boolean)
' Figure out whether the URL requested is on the banned list
' If it is, never show the window or navigate to the site.
' Otherwise, let it through normally.
End Sub
If it's really OK to pop up the window, the second window is activated, made visible, and set as the foreground window.
      We're releasing the source code for our WatchIE program along with the April 2002 code download. Please bear in mind that it's sample code, and as such is crude and unfinished (just like its author). It's written in Visual Basic 6.0. If you can convert this to a version for .NET, maybe we'll feature your work in a future issue!

Author's Corner

      In the March 2002 issue, we printed a top-notch article about Aspect-Oriented Programming (AOP). The authors have asked us to tell you that while the article covers the AOP features provided by COM and .NET, that's just a small sampling of what AOP can provide. For information about everything that AOP can do, check out the resources listed in that article.

Page view tracker