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

  • Home
  • SEARCH
  • 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 8682159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:41:47+00:00 2026-06-12T21:41:47+00:00

I have a WebBrowser control in my C# application. The web browser is under

  • 0

I have a WebBrowser control in my C# application. The web browser is under the user’s control, that is, he can load any web page his computer can access on the web (of course limited by proxy, hosts file and so on).

I need to know and to be notified when there is a Javascript call inside the page loaded in the web browser component.

First example: given a link like this

<a href="javascript:void(0)" onclick="jsFunct();">test</a>

When the user clicks the link I need to know that the function “jsFunct” has been called.

Second example: given a call like

<script type="text/javascript">
    window.setTimeout("jsFunct()", 1000);
</script>

I need to know that, 1 second after the execution of the script, the function jsFunct has been called.

The best thing would be to have an event fired when the function is called. It would also be great if the event could get the Javascript code executed, or at least the function name in the arguments.

EDIT:

Even if the question is related to the webbrowser component, anything that allows the user to detect javascript activation (even via js) would be fine, being able to inject a js that handles the javascript event and passes it to the wb control triggering some event that it can handle.

  • 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-06-12T21:41:48+00:00Added an answer on June 12, 2026 at 9:41 pm

    You can use window.external to call a C# method when a global function is fired in JavaScript. See WebBrowser Control Overview for details on window.external.

    You’ll need to set ObjectForScripting: Webbrowser control’s window.external is ALWAYS null. for this to work.

    Take @Krishna’s answer to add the JavaScript (but drop jQuery because it won’t be needed):

    private void addScript(HtmlElement head, string scriptSource) 
    { 
    HtmlElement lhe_script = head.Document.CreateElement("script"); 
    IHTMLScriptElement script = (IHTMLScriptElement)lhe_script.DomElement; 
    script.src = scriptSource;
    head.AppendChild(lhe_script);            
    } 
    
    addScript(WebBrowser.Head, @"InjectMonitor.js");
    

    The JavaScript below (InjectMonitor.js) will find all global functions and attach your specified handler:

    function augment(withFn) {
        var name, fn;
        for (name in window) {
            fn = window[name];
            if (typeof fn === 'function') {
                window[name] = (function(name, fn) {
                    var args = arguments;
                    return function() {
                        withFn.apply(this, args);
                        fn.apply(this, arguments);
    
                    };
                })(name, fn);
            }
        }
    }
    
    augment(function(name, fn) {
        console.log("calling " + name, fn);
    
        // window.external.yourC#method
    });
    

    In this example, taken from Adding Console Log to Every Function, it just logs the call to console; but using window.external you could send some message back to your C# application with details of what function was called from the client.

    Finally, here’s a JS Bin example (run it and don’t forget the console): JS Bin Example

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

Sidebar

Related Questions

I have a winform application that contains a c# webbrowser control.Webbrower control load a
I have a web page that I display in a WPF WebBrowser control within
I have a C# WPF application with a web browser control (System.Windows.Controls.WebBrowser) called wB.
I have a .NET Winforms web browser control that is rendering some application information,
I have a win forms application that contains a Web Browser control. I need
Okay, I have a WebBrowser control in my VB.NET application that loads a PHP
I have a Windows Forms WebBrowser control embedded in my application. Is there any
I have a WPF application in which I have an embedded web browser control.
I have a web application which is also displayed in a web browser control
I have two applications. In one application the web browser control shows a flash

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.