码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-03-17 14:31:49      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:

      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#后台取值

标签:

原文地址:http://www.cnblogs.com/qigege/p/5287154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!