As a first article, the simple control is used without saying it.
Start with a simple interaction!
C # uses JS functions already in the Web page
WebBrowser.Document.InvokeScript ("Stop"); // WebBrowser is the name of WebBrowser, which is initiated directly through the Invokescipt method of document. parameter is the name of the JS function
This invokescript is a return value that can accept the return value of the page's JS function.
C # Add a new JS function to a Web page
It can also be achieved in WebBrowser.
The basic ideas are:
Create a label.
Fill a value in a label that needs to be populated
Add a label to a Web page
Then see if the situation starts.
var setnewhtml = WebBrowser1.Document.CreateElement ("script"); // Create a label Setnewhtml.setattribute ("text",@ "function Newfun () {alret (' Hello ')} "); // incoming a value to a label WebBrowser1.Document.Body.AppendChild (setnewhtml); // fill to the end of the body of the Web page
C # get the label for a Web page
var getidhtml= webBrowser1.Document.Body.Document.GetElementById (" tag ID" ); // getidhtml.innerhtml Gets the HTML for this tag // Getidhtml.innertext Gets the value of the label
Getidhtml is a htmlelemnt type
The basic of the label can be obtained through this
C # Modify Page content
Ditto, because the methods and properties of the htmlelemnt type are mostly get;set, so you can get the modified
var getidhtml= webBrowser1.Document.Body.Document.GetElementById ("a" ); " <a>AAAABBBB</a> ";
or modify it directly.
WebBrowser1.Document.Body.Document.GetElementById ("a"). SetAttribute ("," "");
This method has two parameters, the first one is to set the name of the parameter, the second is the specific value of the parameter
C # directly uses some of its own properties for labels on Web pages
such as clicks, etc.
WebBrowser1.Document.Body.Document.GetElementById ("a"). InvokeMember ("click");
Simple interaction with the WebBrowser