When reading all over the Internet, there is a great advertisement blocker for FireFox (Adblock Plus). However, where is the one for Internet Explorer?
After "years" of searching for the right Internet Explorer Add-in, I decided to do something good with the time I was just wondering what to do next. So, the idea for Internet Explorer AdBlock was born. Now I only had to finish it, but that isn't the hardest part, right?
Before we begin this article, there are some requirements to meet if you want to compile the source:
Using the Code
First, I will briefly describe some problems I encountered when implementing the Internet Explorer Add-on part of Internet Explorer AdBlock. Then, I will provide some information about the Document Object Model (DOM) which you can use inside the Add-on to loop through the websites.
Internet Explorer Add-on
The first time I had to write an Internet Explorer (or for example Windows Media Player) Add-on, it was hard for me to get a grip on the way things work. For example, where to use the Browser Helper Object (BHO). And what about the user interface (the toolbar)? Can it be integrated into the BHO, or does it need to be implemented in a separate class?
This article about BHO explains what a BHO object is and how to start a BHO project.
I tried to implement the toolbar and the BHO into the same class (object), but that seemed impossible. The reason is that a BHO runs in the background of Internet Explorer, and is enabled via the Add-on settings of Internet Explorer.
The toolbar is a control that can be enabled via the toolbar region itself. However, I wanted the AdBlock to keep blocking advertisements, even if the user decided to hide the toolbar (because once you set the settings correctly, you can hide the blocker and forget about it).
Document Object Model (DOM)
To find all information about DOM, please visit the official website. I will use this section to briefly describe how to use DOM inside the Internet Explorer Add-On.
It is possible to retrieve the current webpage (for Internet Explorer 7: in the current tab) the user is visiting. The webpage is an object of the IHTMLDocument2 Interface. The interface allows any developer to examine and modify the HTML elements inside the document (the webpage).
Internet Explorer AdBlock uses the following main elements of the DOM to block advertisements:
- Frames (webpage inside a webpage, which is a new
One of the main problems of an Internet Explorer Add-on is that it is only possible to get the website after the page is fully loaded. This means that it is impossible to save bandwidth by not downloading any images. When frames are downloaded, and the frame should be fully blocked, it can be blocked thanks to the
OnBeforeNavigate2 function of the DWebBrowserEvents2 Interface.
This point makes it really hard to implement an AdBlock Add-on since the advertisements can be blocked after they are loaded. So, simply said, the user has to download and view the advertisements and then wait for the Add-on to remove and hide them again.
One of the things I tried to improve performance was to implement a cache mechanism. The cache keeps track of all elements handled in a webpage and the amount of times the elements were handled. This way, it is possible to loop through a much smaller array (the cache) for frequently visited websites or elements. But, when an element is not listed in the cache, the add-on first loops through the cache and then loops through the complete black- and whitelist.
Future of Internet Explorer AdBlock
The source in this package is not fully optimized. To be more precise, the reason I decided to release the source to the open-source community is because I couldn't make the source perform much better than it does at the moment. Maybe a smart guy out there (read: you) can optimize it and release this to the public, so Internet Explorer users will finally have some tool to block the irritating advertisements on the Internet.
One of the ideas I had to improve performance (or usefulness of the Add-on) was to modify the stylesheets of the websites instead of looping through the websites. The idea is to download all stylesheets to a cache directory and modify them according to the blocking information provided by the user or any block-list Internet Explorer AdBlock synchronizes with. Then, you can smartly cache frequently visited websites and block standard advertisements without even using any processing power (except for changing the remote CSS URL to a local cached one via DOM).
- 2008-01-18: Initial article