///窗体文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace MyApplication
{
public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();
}
private void MyForm_Load(object sender, EventArgs e)
{
string path = System.Windows.Forms.Application.ExecutablePath;
FileInfo exeInfo = new FileInfo(path);
path = exeInfo.DirectoryName + "\\"; //程序根目录
string file_name = path + "html_file\\myscript.html"; //html带路径文件名 html文件放在debug目录下得html_file文件夹中
MyBrowser.Url = new Uri(file_name);
}
private void MyButton_Click(object sender, EventArgs e)
{
object[] parameters = new object[2];
parameters[0] = 3;
parameters[1] = 2;
MyBrowser.Document.InvokeScript("Add", parameters);//如果javascript方法不带参数 则MyBrowser.Document.InvokeScript("函数名");即可
}
}
}
/页面文件//<html>
<head>
<script type="text/javascript">
function Add(a,b)
{
alert(a+"+"+b+"="+(a+b));
}
</script>
</head>
</html>