Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 383
koalabruder Avatar asked Aug 21 '12 10:08

koalabruder


People also ask

Can WPF be targeted to Web browser?

Can WPF be targeted to Web browser? WPF only runs on Windows. It doesn't run on Mac OS, it doesn't run on Chromebooks, and it doesn't run on mobile devices. WPF requires deployment and installation, it cannot be easily integrated in an intranet, and it doesn't run inside the web browser.

Can we use Javascript in WPF?

You cannot use Javascript to create a WPF application. WPF is a desktop application technology and Javascript are web technologies. WPF has C# in the background (or VB.NET). You can do events, actions, etc.

Can we convert WPF in web application?

If you want to convert your WPF app to ASP.NET Web forms or MVC you would have to do it manually.To make it easier you could create shared code which can be used by both WPF and the web application. Thanks for your reply.In our WPF project we have used MVC pattern.


1 Answers

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

like image 182
koalabruder Avatar answered Sep 28 '22 04:09

koalabruder