I was recently doing a project to make an add-on for Internet Explorer. How do I put it? I must say that was an extremely frustrating experience. The documentation is severely lacking, if not non-existent. One page from MSDN (which states the psarray
is a BSTR
is even dead wrong).
I have never been more motivated to contribute to the scene by writing my own “Internet Explorer add-on writing survival guide” sort of thing, but then I realized Pete has beat me to it by opening an entire [bho-wiki][wiki].
Nevertheless, I’m writing this article so more people can find these scarce information on IE add-on. On the other hand, here are some thoughts I had when writing the IE add-on. If you’re about to write an IE add-on, these would probably be the “survival guides” you’re using (as there aren’t many).
1. An IE add-on is a Browser Helper Object (BHO)
To save you some time searching in vain, try using BHO in your Google searches. This would give you programming-related information instead of where to download the latest IE add-on product.
2. Use C#
C++ just plain sucks, in terms of writing an IE add-on. Don’t get me wrong here, the language is marvelous, but Microsoft’s support just seems broken and unfinished. The whole Win32 hacking, COM stuffs involved when using C++ just makes your life 10 times more difficult.
The interface for C# is much more usable, and you won’t have to deal with all the bullshits when programming in the outdated (and most probably unmaintained) Win32 API.
Another major issue with C++ is Visual C++ 2008 Express. It doesn’t come with ATL, which means a ridiculous amount of grunt work dealing with pointers, releasing and stuffs (as illustrated below, as I happened to use VC++ Express). VC# doesn’t have this problem and it even has a number of libraries built-in (such as regular expressions).
Example 1: getElementById from BHO
Using
C++
IHTMLCollection * elements;
HRESULT hr = document->get_all ( &elements );
assert ( SUCCEEDED ( hr ) );
long numElements; hr = elements->get_length ( &numElements ); assert ( SUCCEEDED ( hr ) );
IHTMLElement * element;
for ( int i = 0; i < numElements; i++ ) { VARIANT index; index.vt = VT_I4; index.intVal = i;
IDispatch * elementDispatch;
hr = elements->item ( index, index, &elementDispatch ); assert ( SUCCEEDED ( hr ) );
hr = elementDispatch->QueryInterface ( IID_IHTMLElement, (void **)&element ); assert ( SUCCEEDED ( hr ) );
elementDispatch->Release();
// After all this hard work, we have finally obtained our element! // GetAttribute is a custom function, I didn't even bother to // list out it's content here if ( GetAttribute ( element, L"id" ) == id ) break; else { element->Release(); element = NULL; } }
elements->Release(); return element;
Using C#
document.getElementById(id);
Example 2: execute some Javascript
Using C++
BSTR code = SysAllocString ( L"alert ( 'Hello World' );" );
BSTR language = SysAllocString ( L"javascript" );
VARIANT result = {0};
window->execScript ( code, language, &result );
SysFreeString ( code );
SysFreeString ( language );
Using C#
window.execScript ( "alert ( 'Hello World' )", "javascript" );
3. Use jQuery for DOM manipulation
jQuery is a client side JavaScript library to simplify common tasks (the “write less, do more” library as they say). I found it delightfully pleasant to use. It has some powerful functions like CSS selectors that would be a pain in the ass to implement in BHO. With jQuery, you can do stuff like:
// Find all the <a> elements with class "bookmark" and
// target attribute "_blank" and hide
// them smoothly using a slow slide up animation
$('a.bookmark[@target="_blank"]').slideUp("slow");
To use jQuery, simply use execScript
to load the jQuery file on document complete.
4. About XmlHttpRequest
Fetching external Web pages using client side JavaScript will give you a permission denied error because of the cross-domain policies of most modern browsers. XmlHttpRequest must be done in the BHO. Sven offers an example code to use IXmlHttpRequest, which is very valuable considering the lack of official documentation. Pete has rolled his own CPeteHttpRequest class using WinHttp.
(Strangely enough, both of the above are coded in C++. I have yet to come across an equally efficient way to do XmlHttpRequest in C#. Please feel free to leave a comment if you have good ideas)
Attractive component of content. I simply stumbled upon your blog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I will be subscribing to your feeds and even I fulfillment you get entry to consistently fast.
I visit every day some web sites and blogs to read posts, but this blog presents feature based posts.
Thanks, I’ve recently been searching for info approximately this subject for a while and yours is the greatest I’ve found out till now. However, what in regards to the bottom line? Are you sure concerning the source?
Wonderful goods from you, man. I’ve understand your stuff previous to and you are just extremely fantastic.
I actually like whqt you have acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and yyou still take care of to keep it smart. I can’t wit to read far more from you. This is really a wonderful web site.
I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the net will be a lot more useful than ever before.
It’s truly very difficult in this active life to listen news on Television, so I just use world wide web for that purpose, and take the latest information.
I have recently started a site, the info you offer on this site has helped me greatly. Thanjs for all of our time & work.
I am inpressed with this internet site, very I am a big fan.
prescription drugs online without doctor – prescription drugs without prior prescription no prescription rx medicine
I am sure this piece of writing has touched all the internet people, its reallky really good article on building up new blog.
reliable canadian pharmacy drugs without a doctor s prescription canada drugs online review
No matter if some one searches for his required thing, thus he/she needs to be available that in detail, so that thing is maintained over here.
Thank yyou a lot for sharing thi with all people you actually know what you are talking approximately! Bookmarked. Please additionally tlk over with my web site =). We could have a hyperlink exchange arrangement among us!
canada online pharmacy reviews – order prescription medicine online without prescription cheapest canadian online pharmacy
canadian pharmacy no presciption medicine from canada with no prescriptions pharmacy drugstore online
Excellent site. Lots of helpful info here. I’m sending it to some buddies ans additionally shating in delicious. And of course, thank you for your effort!
legitimate canadian online pharmacy – drugs without a doctor s prescription top mail order pharmacies
I’ve been absent for a while, but now I remembe why I used tto love this web site. Thank you, I will try and check back more often. How frequently you update your website?
cialis samples for healthcare professionals buy Tadalafil 20mg cialis 20 mg best price
Hey there, I think your blog might bee haing browser compatibility issues. When I look at your blog site in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give youu a quick heads up! Other then that, awesome blog!
cialis daily online buy Cialis 20mg buy 5mg cialis online
I have been absent for soome time, but now I remember why I used to love this wweb site. Thanks, I’ll try and check back more frequently. How frequently you update your site?
generic cialis fedex cheap cialis genic cialis
northwest canadian pharmacy canada rx pharmacy world canadian world pharmacy
indian pharmacy paypal mail order pharmacy india indianpharmacy com
It’s very trouble-free too find out any topic on web as compared tto books, as I found this post at this site.
You actually make it appear really easy together with your presentation however I to find this matter to be actually one thing which I feel I might never understand. It seems too complex and very vast for me. I’m having a look ahead in your subsequent put up, I’ll attempt to get the hang of it!
buy cytotec online buy cytotec in usa Cytotec 200mcg price
indian pharmacy paypal [url=https://indiapharmfd.com/#]top 10 pharmacies in india[/url] Online medicine order