日期:2014-05-19  浏览次数:20815 次

请问。webbrower中如何得到网页中的一个Jscript变量的值
用webborwer导航一个网页,网页中有一个Jscript变量,如何在程序中读取它??

------解决方案--------------------
//项目中添加Micrsoft.mshtml引用
--c:\temp\temp.htm--
<html>
<script language= "JavaScript ">
var Temp = "Zswang 路过 :) ";
</script>
</html>

using mshtml;

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate(@ "c:\temp\temp.htm ");
}

private void button1_Click(object sender, EventArgs e)
{
IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLWindow2 vWindow = vDocument.parentWindow;
vWindow.execScript( "document.title=Temp; ", "JavaScript ");
Text = vDocument.title;
}