软件编程
位置:首页>> 软件编程>> C#编程>> webBrowser执行js的方法,并返回值,c#后台取值的实现

webBrowser执行js的方法,并返回值,c#后台取值的实现

作者:jingxian  发布时间:2023-12-07 13:29:13 

标签:webBrowser,执行,js,返回值

实例如下:


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")

获得值

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com