winform webBrowser

//使网页能够与winform交互 将com的可访问性设置为真
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisible(true)]

 private void Form1_Load(object sender, EventArgs e)
        {
            //webBrowser1.Navigate(new Uri("https://www.cnblogs.com/cmt/p/13966899.html"));
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.ObjectForScripting = this;
            webBrowser1.Navigate(Application.StartupPath + @"	est.html");

            //webBrowser1.Document.InvokeScript("js 的函数名", 参数");
            /*(1)调用html的JS函数
            webBrowser.Document.InvokeScript(“DoAdd”, new object []{ “这个是我要传给前台的值1”,”这个是我要传给前台的值2”});
            注意:DoAdd就是 html的funcation名称
            (2)获取html值
            webBrowser.All[“txtName”].GetAttribute(“value”);
            (3)给html控件赋值
            webBrowser.All[“txtName”].SetAttribute(“value”, “这个是我要赋给他们的值”);
            (4)调用html控件的按钮事件
            webBrowser.All[“txtName”].InvokeMember(“onclick”);
            (5)注册html按钮事件,使它的事件,调用后台事件(建议在webBrowser_DocumentCompleted事件中注册)
            webBrowser.All[“txtName”].Click += new HtmlElementEventHandler(html_btnClouse_Click);
            void html_btnClouse_Click(object sender, HtmlElementEventArgs e)
            {
            this.Close();
            }
            */
        }
        public void Hello()
        {
            MessageBox.Show("html调用wf函数成功!");
        }
原文地址:https://www.cnblogs.com/horizonhz/p/14004464.html