Simple interaction with the WebBrowser

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.