I have two applications:
I want to make them coexist so i'm considering integrating a WebBrowser ActiveX control in my .net application. I want to understand how "deep" i can make them communicate and more specifically:
Which type of information can i send from the webapp to parent .net app?
In Microsoft documentation, several events are associated to the WebBrowser
class like Navigated
which seems to be triggered every time the webapp's url changes. So i can imagine a mechanism which:
hello
was triggered with content you
. That sounds like a tedious process, so:
window.postMessage
method? I think you can build a bridge between javascript code in modern application and your C# host application using this technique https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/implement-two-way-com-between-dhtml-and-client
It allows to execute C# code from JS as well as invoke JS from C#. You need to set ObjectForScripting
property of WebBrowser control to C# object, methods of which will be called and then invoke it like
window.external.YourCSharpObjectMethod('called from JS code');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.