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

Posted on 2006-05-26
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
    LVL 22

    Expert Comment

    >>is this called an agent ?.

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

    LVL 22

    Expert Comment

    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 : <==

    LVL 10

    Author Comment


    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

    Above sample code shows accessing individual elements using DOM only...There is another article at codeguru 'Viewing the IE Document Object Model ' <==

    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 : <=========**

    Other sample BHO projects in VC++ :

    Hope This Helps


    LVL 22

    Expert Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now