webBrowser executes the method of js and returns the value and the realization of background value of c

  • 2021-11-14 06:50:52
  • OfStack

Examples are as follows:


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"," Top 1 A ","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>

Using the html page as a medium, the returned value is passed to the control in html, and then used in webBrowser


HtmlElement element = webBrowser1.Document.GetElementById("msg");
        txtInfo.Text = element.GetAttribute("value")

Get a value


Related articles: