Search code examples
c#internet-explorerbhobrowser-extension

How do I append child node in an Internet Explorer BHO extension?


I am porting a firefox extension and simply trying to append a button to an node on a web page. However nothing occurs on the page. I believe it has to do something with the conversion between HTMLDOMNode and the HTMLElement. I don't even get any errors inside console using IE dev add on.

My code:

public void OnDocumentComplete(object pDisp, ref object URL)
    {
        HTMLDocument document = (HTMLDocument)webBrowser.Document;
        var fblike = document.getElementById("LikePluginPagelet");

        var button = document.createElement("input");
        button.setAttribute("value", "myButton");
        button.setAttribute("onClick", "doSomething()");
        ((IHTMLDOMNode)fblike).appendChild((IHTMLDOMNode)button);
    }

Solution

  • You need to make fblike dynamic.

    public void OnDocumentComplete(object pDisp, ref object URL)
    {
        HTMLDocument document = (HTMLDocument)webBrowser.Document;
        var fblike = document.getElementById("LikePluginPagelet");
    
        var button = document.createElement("input");
        button.setAttribute("value", "myButton");
        button.setAttribute("onClick", "doSomething()");
    
        dynamic fbLike = fblike
        fbLike.appendChild((IHTMLDOMNode)button);
    }