4. Initialize the Url and ObjectForScripting properties of WebBrowser.
Url property: The path of the web page displayed by the WebBrowser control
ObjectForScripting property: This object can be accessed by the script code contained in the web page displayed in the WebBrowser control.
Set the Url attribute to the URL path of the page that needs to be operated.
JavaScript calls methods exposed by C# through window.external. That is, the public methods contained in the instance of the class set by the ObjectForScripting property. Specific setting examples are as follows:
System.IO.FileInfo file = new System.IO.FileInfo("index.htm");
// Web page path displayed by the WebBrowser control
webBrowser1.Url = new Uri(file.FullName);
// Set the current class to be accessible by scripts
webBrowser1.ObjectForScripting = this;
5. C# calls the JavaScript method
Call the JavaScript method of the current web page through the InvokeScript method in the Document property of the WebBrowser class. For example:
// Call JavaScript’s messageBox method and pass in the parameters
Dnew.cn Note: Original text: http://www.cnblogs.com/xds/archive/2007/03 /02/661838.html
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn