Simply put, load a webBrowser1 in the C # client WinForm and then trigger the C # function response with the Click JS effect on the page in WebBrowser1. The pro-test passed.
The C # code is as follows:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace testjs{ [ System.Security.Permissions.PermissionSet (System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] [System.Runtime.InteropServices.ComVisibleAttribute (true)] public partial class Form1:form { public void Say () { MessageBox.Show ("OK"); } Public Form1 () { InitializeComponent (); } private void Form1_Load (object sender, EventArgs e) { this.webBrowser1.ObjectForScripting = this; This.webBrowser1.Navigate ("http://localhost/1.html");}}}
The JS code is as follows:
<script>
function Say ()
{
var tnum=window.external.say ();//getdebugpath () is a C # method
}
</script>
Hi
<input type= "button" value= "OK" onclick= "Say ()" >
Tests can be output