Click here to Skip to main content
15,178,008 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello, I am using the WebBrowser control in an application for it's user interface. So far I have been using links (#something) and the Navigating event of the WebBrowser so that the app knows what to do when the user clicks a link, however I have seen some applications that has the WebBrowser control embedded and use javascript to talk with the app (the link is visible, it's something like javascript:"some_function();").
My question is how to should I create custom javascript functions that map to functions from inside the app (built with c#, something like a javascript API for the app).
Thanks for your help :)

1 solution

WebBrowser Control has a property named ObjectForScripting. You can assign it to any object whose class is marked as Com Visible.
That object will be exposed to javascript code as window.external. You can call any method exposed by the original object.

For reference and examples, look here: System.Windows.Forms.WebBrowser.ObjectForScripting[^]

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900