Add JavaScript Functions OnDocumentComplete

Add-in Express™ Support Service
That's what is more important than anything else

Add JavaScript Functions OnDocumentComplete
How to add JavaScript functions to the head of a document after OnDocumentComplete 

Posts: 1
Joined: 2012-03-14
Loading JavaScript functions OnDocumentComplete

I am very new to C#, IE BHOs and Add-in Express for Internet Explorer.
I am trying to build an ADX IE add-on in C# that loads a Javascript function set into the head of the document after the browser loads a page.

By research I have come up with the code:
public void OnDocumentComplete(object pDisp, ref object URL)
HTMLDocument document = (HTMLDocument)webBrowser.Document;

IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)document.all.tags("head")).item(null, 0);

IHTMLScriptElement headScript = (IHTMLScriptElement)document.createElement("script");

headScript.text = "alert('Hi!')";



Is this code even close for what I am trying to do?
What part of this code will need to be modified?
What References would I need to add to make this work?
If I am going in a completely wrong direction please point me in a correct direction, with code samples if possible.

Thank you very much,
Gary A Johnson
Posted 14 Mar, 2012 13:20:33 Top
Eugene Astafiev


Hi Gary,

Please take a look at the HOWTO section of our web site. It provides the How to run and replace a script (JavaScript, JScript or VBScript) on an HTML page in IE 6 or 7 sample add-on project. Is it what you are looking for?
Posted 15 Mar, 2012 02:55:41 Top