SpicIE dynamically adding elements to Document object

See code below:

Using SpicIE's OnDocumentComplete event
void SpicIE1_OnDocumentComplete(object pDisp, ref object url)
        {
            if (url.ToString().IndexOf("msn") > 0)
            {
                if (pDisp is IWebBrowser2)
                {
                    try
                    {
                        var webBrowser = pDisp as IWebBrowser2;
                        var doc2 = webBrowser.Document as IHTMLDocument2;

                        var element = doc2.createElement("h1");
                        element.innerHTML = "Hello World";
                        element.setAttribute("style", "border: 1px solid red;", 1);
                        
                        doc2.body.insertAdjacentHTML("beforeBegin", element.outerHTML);
                        doc2.close();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Plugin is not loaded properly.");
                    }
                }
            }
        }
SpicIE dynamically adding elements to Document object SpicIE dynamically adding elements to Document object Reviewed by Edward Legaspi on Monday, February 14, 2011 Rating: 5

No comments:

Powered by Blogger.