1.c#程序里要添加 [System.Runtime.InteropServices.ComVisibleAttribute(true)] 和 webBrowser1.ObjectForScripting = this;
位置:
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
refresh();
string path1 = System.Windows.Forms.Application.StartupPath + @"\" + "PlanMngPage" + @"\home.htm";
webBrowser1.Navigate(new Uri(path1));
webBrowser1.ObjectForScripting = this;
}
public void MyMessageBox(string message)
{
MessageBox.Show(message);
}
2.在JS使用 window.external.引用的窗体的函数(); 来引用C#里的函数
eg:
<body οnlοad="window.external.MyMessageBox('javascript访问C#代码')">