WebBrowser executes the JS method, and returns the value, C # background value

Source: Internet
Author: User

      Private void Form1_Load (object  sender, EventArgs e)        {            @ "\i.html");            = webbrowser1.documenttext;        }
Private voidButton2_Click (Objectsender, EventArgs e) {WebBrowser1.Document.InvokeScript ("GetCode",New Object[] {"1567613","228267824","Top One","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), +, SessionID);}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"><HTML>    <Head>        <title></title><Scripttype= "Text/javascript"src= "I.js"></Script>    </Head>    <Body>    <inputtype=textID=msg/>    </Body></HTML>

Use an HTML page as the medium to pass the returned value to the control in the HTML, and then in WebBrowser

HtmlElement element = WebBrowser1.Document.GetElementById ("msg");                Txtinfo.text = element. GetAttribute ("value")       
Get value

WebBrowser executes the JS method, and returns the value, C # background value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.