Fady Sayegh
Posts: 7
Joined: 2012-09-12
|
Hi All,
i'm trying to ad a script to the head tag of a document. however i'm always having a null value after getting the head tag for the element collection.
please check the below snipped code and point me in the right direction.
mshtml.HTMLDocument oHtmlDoc = this.HTMLDocument;
mshtml.HTMLHeadElementClass oHtmlHead = ((mshtml.IHTMLElementCollection)oHtmlDoc.all.tags("head")).item(null, 0) as mshtml.HTMLHeadElementClass;
if (oHtmlHead != null)
{
mshtml.IHTMLScriptElement script = ((mshtml.IHTMLScriptElement)oHtmlDoc.createElement("script"));
script.type = "text/javascript";
script.text = "SOME SCRIPT";
oHtmlHead.appendChild(((mshtml.IHTMLDOMNode)script));
}
can you please indicate what is the problem with the above code.
Best regards and thanks in advance
Fady Sayegh |
|
Eugene Astafiev
Guest
|
Hi Fady,
I have just tried to run your code on my PC with Internet Explorer 9 installed and couldn't reproduce the issue. Your code works without any exceptions or error messages. Also please take a look at the similar Cannot inject the script forum thread. Did you try to use the code listed there? |
|