Calling a Javascript function in the C# webBrowser control

后端 未结 2 1900
走了就别回头了
走了就别回头了 2020-11-29 09:24

I am using the webBrowser control in C# to load a webpage and need to call a JavaScript function that returns a string value. I got a solution to use the

2条回答
  •  天命终不由人
    2020-11-29 09:43

    Can you specify what failed?

    My sample below consists of a form with a WebBrowser and a Button.

    The object called y in the end has the sentence "i did it!". So with me it works.

    public partial class Form1 : Form
        {
    
            public Form1()
            {
                InitializeComponent();
    
                webBrowser1.DocumentText = @"
                    
                    hello!";
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                object y = webBrowser1.Document.InvokeScript("doIt");
            }
        }
    

提交回复
热议问题