954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

monitor Javascript running in C# WebBrowser control

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.

JDoggieIII
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
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);
JDoggieIII
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: