The webbrowser of WPF differs from that of winform.
To inject a Javascript script into it, after my own test, the following path can be used:
Mshtml. htmldocument htmldoc = browser. document as mshtml. htmldocument; <br/> var head = htmldoc. getelementsbytagname ("head "). cast <ptmlheadelement> (). first (); <br/> var script = (ihtmlscriptelement) htmldoc. createelement ("script"); <br/> script. TEXT = "alert ('Hello World')"; <br/> head. appendchild (ihtmldomnode) script );
This method can also inject Javascript functions and call browser. invokescript () as needed.
But today I found a strange problem .. I used this injection method to modify document. Body. style. Zoom. The whole page is scaled, but the flash and other controls are faulty ..
Then I used the developer tool in IE8 to inject and modify document. Body. style. Zoom...
That's strange. I will continue the study the next day.