随机代码

1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Runtime.InteropServices;
10namespace web_and_js
11{
12    //基类也要COM可见
13    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
14    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
15    public partial class 与JS通讯 : Form
16    {
17        public 与JS通讯()
18        {
19            InitializeComponent();
20        }
21        private void 与JS通讯_Load(object sender, EventArgs e)
22        {
23            string texturl = Application.StartupPath + "/与JS通讯/text.html";
24            this.webBrowser1.ObjectForScripting = this;
25            this.webBrowser1.Navigate(texturl);
26        }
27        //外部JS执行函数
28        public void WinFormMessage(string str)  
29        {
30            MessageBox.Show(str, "获取JS函数数据:");
31        }
32        //外部JS获取函数
33        public string WinFormRetustr() 
34        {
35            string str = "您获取到的是C#WinFormRetustr()函数";
36            return str;
37        }
38
39    }
40}
参考地址:C#WinForm与JS通讯

代码交流 2021