C#WinForm与JS通讯

1、与JS基本通讯原理

CS 代码

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;
using System.Runtime.InteropServices;
namespace web_and_js
{
    //基类也要COM可见
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class 与JS通讯 : Form
    {
        public 与JS通讯()
        {
            InitializeComponent();
        }
        private void 与JS通讯_Load(object sender, EventArgs e)
        {
            string texturl = Application.StartupPath + "/与JS通讯/text.html";
            this.webBrowser1.ObjectForScripting = this;
            this.webBrowser1.Navigate(texturl);
        }
        //外部JS执行函数
        public void WinFormMessage(string str)  
        {
            MessageBox.Show(str, "获取JS函数数据:");
        }
        //外部JS获取函数
        public string WinFormRetustr() 
        {
            string str = "您获取到的是C#WinFormRetustr()函数";
            return str;
        }

    }
}

HTML代码





C#WinForm与JS通讯





你可能感兴趣的:(c#,通讯)