Search code examples
javascripthtmlwpfdom-eventswpf-controls

Is it possible to invoke a C# method from Java script from WPF Web browser control?


I'm using a Tab control in WPF and the Tab control contains a WebBrowser control in first tab. I have some scripts and HTML content for the Webbrowser control and this works fine. Also I'm able to invoke the script method written inside the HTML content, but I need the vice versa as need to invoke a C# method from Javascript method.

Is it possible?


Solution

  • You can specify an object which is accessible to be called directly from your JavaScript. Check out the property ObjectForScripting on the WebBrowser control for more information.

    Also, here is another post which outlines it even better: Hosting and interacting with a webpage inside a WPF App