標籤:
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#後台取值