How to communicate between WPF and JavaScript in a WebBrowser instance?

koalabruder picture koalabruder · Aug 21, 2012 · Viewed 23.9k times · Source

I have a C#/WPF application with an embedded browser (WebBrowser) with some JavaScript. How can they communicate with each other in both directions? Is it practicable to use the URL?

JS->WPF: Listen for changes. WPF->JS: Change the URL to javascript:alert('hello');

Is there a better way?

Answer

koalabruder picture koalabruder · Aug 22, 2012

It's important to know that there are two WebBrowser. One for Windows Forms and one for WPF. The link below uses the WPF one. http://www.dotnetfunda.com/articles/article840-working-with-webbrowser-in-wpf.aspx