
//项目中添加Micrsoft.mshtml引用 |
//Begin temp.htm------- |
<html> |
<head> |
<title>demo</title> |
<script language="JavaScript" type="text/javascript"> |
var testText = "Zswang"; |
function ShowMessage(AText) |
{ |
alert(testText); |
alert(AText); |
} |
</script> |
</head> |
</html> |
//End temp.htm------- |
using mshtml; |
using System.Reflection; |
private void button1_Click(object sender, EventArgs e) |
{ |
IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2; |
IHTMLWindow2 vWindow = (IHTMLWindow2)vDocument.parentWindow; |
Type vWindowType = vWindow.GetType(); |
object testText = vWindowType.InvokeMember("testText", |
BindingFlags.GetProperty, null, vWindow, new object[] { }); // 读取 |
Console.WriteLine(testText); |
vWindowType.InvokeMember("testText", |
BindingFlags.SetProperty, null, vWindow, new object[] { "stephen.kang 路过" }); // 设置 |
vWindowType.InvokeMember("ShowMessage", |
BindingFlags.InvokeMethod, null, vWindow, new object[] { 12345 }); // 执行方法 |
} |
private void button2_Click(object sender, EventArgs e) |
{ |
IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2; |
IHTMLWindow2 vWindow = (IHTMLWindow2)vDocument.parentWindow; |
vWindow.execScript("ShowMessage(67890);", "JavaScript"); // 执行脚本 |
} |
目前已经有最新的版本,不同于以上方法制作的工具: |
见我的博客:http://www.cnblogs.com/axing/archive/2012/10/29/stephen_kang_WinForm.html |




by: 发表于:2018-01-29 11:01:40 顶(0) | 踩(0) 回复
??
回复评论