How can I call the JavaScript function on the page viewed by the WebBrowser control from the application that the WebBrowser control is on?

I created a C # desktop application that depends on the idea of ​​a web crawler.

I made my application using a web browser control to open a website and log in progmatically and redirect to a specific page that has a gridview with all the user data that I want to collect ...

But here the username in the gridview click is triggered by the JavaScript function. I know his name, but not what to call him inside the desktop application.

What are the namespaces or DLLs that would allow me to do this?

+3
source share
2 answers

I think this should help you:

http://www.west-wind.com/WebLog/posts/493536.aspx

EDIT: Based on this link, here is a small sample application. Add a Button and WebBrowser control to your Windows form and add this code:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.webBrowser1.DocumentText = @"<html>
<body>
<script type = ""text/javascript"">
function ShowMessage(text) {
   alert(text);
}
</script>
</body>
<input type=""button"" onclick=""ShowMessage('From JavaScript')"" value=""Click me""/>
</html>";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.webBrowser1.Document.InvokeScript("ShowMessage",new object[]{"From C#"});
        }
    }

If you click the button in the browser, it will show the javascript message, if you click the button in the form of a window, it will show the C # message.

+8
source

Do you think the following is used to run the script on the page: WebBrowsercontrol?

' In VB - but easy to convert to C# as its pretty much the same thing :).
Dim sScript As String, sLanguage As String
sLanguage = "JScript"
sScript = "MyJavaScriptToRun();" ' you can run many lines by delimiting them with ;

WebBrowser1.Document.parentWindow.execScript sScript, sLanguage

, . .NET- WebBrowser script, , .RunScript ( , , intellisense).

, .

0

Source: https://habr.com/ru/post/1711191/


All Articles