111,088
社区成员




<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function add(str1, str2) {
alert(str1);
}
//add('aaa', 'bbb');
</script>
</head>
<body>
</body>
</html>
C#代码
private void button1_Click_1(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
webBrowser1.Url = new Uri(string.Format("file:///{0}/HTMLPage2.html", curDir));
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("add", new object[] {"22222", "ffffff"} );
}
// 首先去创建两个 js 里面的对象
object arrSong1 = webBrowser1.Document.InvokeScript("eval", new object[] { "new Array('121.48', '120.69')"});
object arrSong2 = webBrowser1.Document.InvokeScript("eval", new object[] { "new Array('31.22', '30.40')"});
// 然后再调用
webBrowser1.Document.InvokeScript("add", new object[] { arrSong1, arrSong2});
// 对数组操作都用 InvokeMember 的方式
arrSong1.GetType().InvokeMember("push", InvokeMethod, null, arrSong1, new object[] {222});
最好的办法还是修改一下脚本(如果页面是自己做的),别来回传这么复杂的东西