I have been playing around with webkit.net in a c# win forms project, and love how easy it is to call JavaScript functions from within the C# program with:
browser.Document.InvokeScriptMethod("functionName", new object[]{"parameter1", "parameter2"});
Now the question is how to do this the other way round… Is there some sort of event listener that can listen for a javascript function call, or any way to invoke a c# method via the JavaScript running in the webkit browser?
The way I’m doing it at the moment it using a bad hack … having a look at the available event listeners, I hooked up to the TitleChanged event, and read the value of a hidden input field in the html …. this is really bad and needs an actual solution.
Thanks in advance,
– Greg.
This may not pass your Ugly Hack test, but is an ancient method for processing requests from a .net embedded browser. Essentially you intercept a URL GET request in the browser. If the URL contains a keyword (such as app://), you cancel the GET and process the URL parameters. Returning a value, was traditionally accomplished by calling the Navigate Method, however, using the method you described in your post, you can just directly call a javascript function.