Access to web page DOM from Internet Explorer "add-on"

Posted on 2006-05-26
Medium Priority
Last Modified: 2013-11-20

It's been a loooong time since I was doing microsoft coding but I still have Visual Studio .net and I would like to build an IE add-on:

What I want is a program running within IE that accesses the DOM of every page that I am browsing (is this called an agent?). It would be nice to have an on/off switch but I'll save that for another question.

Can someone please give me a step by step on how I can get started?  Links to relevant tutorials & api's would also be very much appreciated.  

Question by:0h4crying0utloud
  • 4
LVL 22

Expert Comment

ID: 16770681
>>is this called an agent ?.

Probably you need to develop BHO ( Browser helper Object ) for this...

LVL 22

Expert Comment

ID: 16770753
you need code to All Enumerate the HTML elements in page.. you may HTMLDocument2::get_all() for this...

code will be something like this :

    //grabbing all elements of the page
      //Enumerate the HTML elements
                IHTMLElementCollection* pColl = NULL;
                hr = pHTMLDocument2->get_all( &pColl );
                if (hr == S_OK && pColl != NULL)
                    LONG celem;
             //Find the count of the elements
                    hr = pColl->get_length( &celem );

                    if ( hr == S_OK )
                        //Loop through each elment

                        for ( int i=0; i< celem; i++ )
                            VARIANT varIndex;
                            varIndex.vt = VT_UINT;
                            varIndex.lVal = i;
                            VARIANT var2;
                            VariantInit( &var2 );
                            IDispatch* pDisp;
                            hr = pColl->item( varIndex,  var2, &pDisp );//Get an element

                            if ( hr == S_OK )
                                IHTMLElement* pElem;
                                hr = pDisp->QueryInterface( IID_IHTMLElement,(void **)&pElem);
                                if ( hr == S_OK )
                                    BSTR bstr;
                                    //Get the tag name for the element
                                    hr = pElem->get_tagName(&bstr);
                                    CString strTag;
                                    strTag = bstr;
                                    //We need to check for
                                    //input elemnt on login screen
                                    IHTMLInputTextElement* pUser;
                                    hr = pDisp->QueryInterface(
                                        (void **)&pUser );

                                    if ( hr == S_OK )
                                       // Got elements Do stufff here...

Refer this example project with src code..specially look at CYahooDlg::OnBnClickedButton1() function :
http://www.codeproject.com/com/DHTML_Interfaces.asp <==

LVL 10

Author Comment

ID: 16772419

That doesn't sound right Mahesh, In my own search I found access to the DOM is as simple as

IHTMLDocument2 document = (IHTMLDocument2)webBrowser.Document;

I just want to get access to the DOM, not reconstruct it. Then I can get individual elements like so:

object sigObj = document.all.item(destElemId, 0);

I still don't even know how to start this project in VS.NET is there a BHO project?

LVL 22

Accepted Solution

mahesh1402 earned 2000 total points
ID: 16774345
Above sample code shows accessing individual elements using DOM only...There is another article at codeguru 'Viewing the IE Document Object Model '
http://www.codeguru.com/Cpp/COM-Tech/atl/misc/article.php/c3619/ <==

Well BHO ie. Browser Helper Object or IE Extension Object is yor IE add-in in which you are goin to construct above functionality...Above article with src code includes such ATL BHO for sample.. Well but i dont have any exact implemented sample in VS.NET yet ! BUT there is another article at codeguru about BHO 'Porting Legacy Browser Helper and IE Extension Objects to .NET ' which Peek Document Object Model from Browser Helper Object !!
Refer : http://www.codeguru.com/csharp/.net/net_general/article.php/c4671/ <=========**

Other sample BHO projects in VC++ :

Hope This Helps


LVL 22

Expert Comment

ID: 16774389
Here is an another BHO project with src which create a DOM extension with the BHO  'Popup Blocker'


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question