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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.