currently I am writing an Plugin for the Internet Explorer in C#.
It is my first try with .net and the Internet Explorer Plugin.
C# has nice language features in comparison to Java.
However, I am stuck. I can’t find an easy/or a way in general to modify the DOM.
My Plugin should have a function to display a Html header to a site.
In Javascript I would do something like this:
var a = document.createElement('a');
var text_node = document.createTextNode(text);
var href = document.createAttribute("href");
href.nodeValue = url;
a.setAttributeNode(href);
a.appendChild(text_node);
var my_dom = document.createElement('div');
my_dom.appendChild(a);
my_dom.style.background = '#36b';;
document.body.insertBefore(my_dom, document.body.firstChild);
I used the tutorial at http://www.codeproject.com/KB/cs/Attach_BHO_with_C_.aspx to get familiar with BHO and Internet Explorer Development. However in this plugin the package mshtml is used to access the dom. I can’t find a good way through the api to add new elements to the dom.
While searching through the net I discovered that the System.Windows.Forms.HtmlDocument has a appendChild Function. However when I transform my program to System.Windows.Forms it does not work at all.
Can somebody show me a way how I can modify (insert at the beginning of the body an html element) the dom?
Here is a link to the skeleton of my programm https://gist.github.com/fd4459dc65acd7d167b6
For the beginning it is enough to show me a way how i can add an to the beginning of the body in the OnDocumentComplete function.
Thank you
After searching and searching I found a solution.
I did not find a way to modify the DOM via mshtml, but via javascript.
Javascript can be injected via
I could reuse my existing javascripts to solve this issue.