this.webBrowser1.ObjectForScripting = new OprateBasic();
this.webBrowser1.Source = new Uri(Environment.CurrentDirectory + @"\template.html");
WPF把数据传给js:
webBrowser1.InvokeScript("msg", objects);
js控制WPF的方法:
[System.Runtime.InteropServices.ComVisible(true)] // 将该类设置为com可访问
public class OprateBasic
{
public void palymusic(string msg)
{
MessageBox.Show(msg);
}
}
注意:
this.webBrowser1.ObjectForScripting = this; 会报错,需重新定义一个类:如OprateBasic,并把js要调用的方法放在这个类中