Html Run Form:
[System.Runtime.InteropServices.ComVisible(true)] //Open ComVisible
//Create Html Page
this.webBrowser1.ObjectForScripting = this; //Get Form_Window Obj
this.webBrowser1.Navigate("");
this.webBrowser1.Document.Write("<html><head>");
this.webBrowser1.Document.Write("<script type='text/javascript'>");
this.webBrowser1.Document.Write("function HtmlJs(){window.document.getElementById('b1').innerHTML+='执行Js脚本,写Html页面'}");
this.webBrowser1.Document.Write("</script>");
this.webBrowser1.Document.Write("</head><body id='b1'>");
this.webBrowser1.Document.Write("<input type=button value='测试'id='bt1' onclick='javascript:{window.external.test()}'>");// Html_Page Run Form_Window Function [test]
this.webBrowser1.Document.Write("</body></html>");
//Form_Window Function
public void test() // Public is Must!
{
MessageBox.Show("执行窗体函数");
}
Form Run Html:
webBrowser1.Document.InvokeScript("HtmlJs"); // Form_Window Run Html_Page JsFunction[HtmlJs]