实例如下: private void Form1_Load(object sender, EventArgs e) { webBrowser1.Navigate(Application.StartupPath + @"\i.html"); txtInfo.Text = webBrowser1.DocumentText; } private void button2_Click(object sender, EventArgs e) { webBrowser
实例如下:
private void Form1_Load(object sender, EventArgs e) { webBrowser1.Navigate(Application.StartupPath + @"\i.html"); txtInfo.Text = webBrowser1.DocumentText; }
private void button2_Click(object sender, EventArgs e) { webBrowser1.Document.InvokeScript("GetCode", new object[] { "1567613","228267824","顶一个","D7D796981B62D318"}); if (webBrowser1.Document.GetElementById("msg") != null) { HtmlElement element = webBrowser1.Document.GetElementById("msg"); txtInfo.Text = element.GetAttribute("value"); } }
function GetCode(lBdId, lDocId, text, sessionID) { document.getElementById("msg").value = H2(lBdId + '-' + lDocId + '-' + P(text), 16, sessionID); }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title><script type="text/javascript" src="i.js"></script> </head> <body> <input type=text id=msg /> </body> </html>
以html页面作为媒介,将返回的值传递到html中的控件,然后在webBrowser中用
HtmlElement element = webBrowser1.Document.GetElementById("msg"); txtInfo.Text = element.GetAttribute("value")
获得值
以上这篇webBrowser执行js的方法,并返回值,c#后台取值的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。