如何通过webBrowser调用JavaScript函数并获取其返回结果?

2026-05-23 20:081阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计281个文字,预计阅读时间需要2分钟。

如何通过webBrowser调用JavaScript函数并获取其返回结果?

示例代码如下:

csharpprivate void Form1_Load(object sender, EventArgs e){ webBrowser1.Navigate(Application.StartupPath + @\index.); txtInfo.Text=webBrowser1.DocumentText;}

private void button2_Click(object sender, EventArgs e){ webBrowser1.Navigate(http://www.example.com);}

实例如下:

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#后台取值的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

如何通过webBrowser调用JavaScript函数并获取其返回结果?

本文共计281个文字,预计阅读时间需要2分钟。

如何通过webBrowser调用JavaScript函数并获取其返回结果?

示例代码如下:

csharpprivate void Form1_Load(object sender, EventArgs e){ webBrowser1.Navigate(Application.StartupPath + @\index.); txtInfo.Text=webBrowser1.DocumentText;}

private void button2_Click(object sender, EventArgs e){ webBrowser1.Navigate(http://www.example.com);}

实例如下:

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#后台取值的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

如何通过webBrowser调用JavaScript函数并获取其返回结果?