mshtml – changing innerHtml of an element
May 25, 2010 Leave a comment
This has turend out to be a wery pesky problem,.. i just wanted to add to javascript tags that i was reading from another web-page.. But as it tuns out you cant just do it,.. So if you do something like this ,.. it woud not work ,.. innerhtml will not be updated.
HTMLScriptElementClass script = (HTMLScriptElementClass)html.createElement("script"); script.innerHTML = "/**/";
So i decided on another approach (c: If i could not access it, i would make my own,..
//get the html element HTMLScriptElementClass script = (HTMLScriptElementClass)html.createElement("script"); script.setAttribute("type", (object)"text/javascript", 0); script.setAttribute("id", (object)id, 0); ((HTMLBodyClass)html.body).appendChild(script); // make your own element which holds the changed element object oScript = html.GetType().GetMethod("getElementById").Invoke(html, new object[] { (object)id }); oScript.GetType().GetProperty("text").SetValue(oScript, "/**/", null); // remove the old element to the DOM html.removeChild((HTMLScriptElementClass)html.getElementById(id)); // insert your own element in to the DOM html.Document.Body.AppendChild (element);
well that’s how I did it ,.. and if you are wondering how to read DOM from other pages using .Net take a look at this ,.. (c:
http://cambridgecode.blogspot.com/2009/11/simple-html-parsing-code-using-mshtml.html
Cheers and out.