This is to set the class to COM accessible. If you do not make this declaration, there will be an error. The error message is shown in the following illustration:
4. Initializes the WebBrowser URL with objectforscripting two properties.
URL Properties: The page path displayed by the WebBrowser control
ObjectForScripting property: This object can be accessed by scripting code that is contained in the Web page that is displayed in the WebBrowser control.
Set the URL property to the URL path of the page you want to manipulate.
JavaScript uses window.external to invoke C # exposed methods. That is, the public method contained in an instance of the class set by the ObjectForScripting property. Examples of specific settings are as follows:
System.IO.FileInfo file = new System.IO.FileInfo ("index.htm");
The page path displayed by the WebBrowser control
Webbrowser1.url = new Uri (file. FullName);
Sets the current class to be accessible by script
Webbrowser1.objectforscripting = this;
5. C # calls JavaScript method
Invokes the JavaScript method of the current Web page through the Invokescript method in the document property of the WebBrowser class. Such as:
Call the JavaScript MessageBox method and pass in the argument
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