Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6547985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:53:47+00:00 2026-05-25T11:53:47+00:00

In my WinForms application I need to call javascript function from my WebBrowser control.

  • 0

In my WinForms application I need to call javascript function from my WebBrowser control. I used Document.InvokeScript and it works perfect with functions alone e.g

Document.InvokeScript("function").

But when i want to call javascript object method e.g.

Document.InvokeScript("obj.method")

it doesn’t work. Is there a way to make it work? Or different solution to this problem? Without changing anything in the javascript code!

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:53:47+00:00Added an answer on May 25, 2026 at 11:53 am

    The example in the documentation does NOT include the parenthesis.

    private void InvokeScript()
    {
        if (webBrowser1.Document != null)
        {
            HtmlDocument doc = webBrowser1.Document;
            String str = doc.InvokeScript("test").ToString() ;
            Object jscriptObj = doc.InvokeScript("testJScriptObject");
            Object domOb = doc.InvokeScript("testElement");
        }
    }
    

    Try

    Document.InvokeMethod("obj.method");
    

    Note that you can pass arguments if you use HtmlDocument.InvokeScript Method (String, Object[]).

    Edit

    Looks like you aren’t the only one with this issue: HtmlDocument.InvokeScript – Calling a method of an object . You can make a “Proxy function” like the poster of that link suggests. Basically you have a function that invokes your object’s function. It’s not an ideal solution, but it’ll definitely work. I’ll continue looking to see if this is possible.

    Another post on same issue: Using WebBrowser.Document.InvokeScript() to mess around with foreign JavaScript . Interesting solution proposed by C. Groß on CodeProject:

    private string sendJS(string JScript) {
        object[] args = {JScript};
        return webBrowser1.Document.InvokeScript("eval",args).ToString();
    }
    

    You could make that an extension method on HtmlDocument and call that to run your function, only using this new function you WOULD include parenthesis, arguments, the whole nine yards in the string you pass in (since it is just passed along to an eval).

    Looks like HtmlDocument does not have support for calling methods on existing objects. Only global functions. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls
I'm using an MVC pattern in winforms application. I need to call remote service
I need to take an existing winforms application and drop into an event tracing
I'm facing the need to enter ragged data in a WinForms application. Some columns
I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to
I am developing a Windows .NET application (WinForms) and I need to simulate a
I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell
I have a C# 3.0 WinForms application which is occasionally required to control Excel
I have a win forms application that contains a Web Browser control. I need
I have build an C# Winforms application which will need regular updates and patches

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.