I am attempting to use a WebBrowser control in C# to display a webpage. I would like my C# application to know when a Javascript function is called within the loaded webpage. Is there anyway to do this? I can't seem to find an event handler for it.

I am attempting to use a WebBrowser control in C# to display a webpage. I would like my C# application to know when a Javascript function is called within the loaded webpage. Is there anyway to do this? I can't seem to find an event handler for it.

If you have access to the javascript code you can call C# functions from javascript. It's not too difficult of a process, but it does contain a few steps.

In C# code:
* The function you wish to call must be written. (obviously)
* The class containing the function must be visible to the javascript. These two lines of code will do the trick:

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]

In javascript:
* Add a line to call the C# function, like so:

window.external.InvokedFromJavascript(arguments);
This question has already been answered. Start a new discussion instead.