4

I'd like to know whether it's possible to pass data from a C# application (e.g. WPF) to a web-page (i.e. an HTML page with Javascript) in an embedded Web Browser. If so, how?

Thanks in advance for your help!

2
  • What exactly are you trying to accomplish? Why don't you just pass the variables to PHP? The question is too broad, but yes, it is possible. Commented Dec 29, 2012 at 0:21
  • I need to interface with some code written in Javascript. What I was wondering specifically is how I might pass a "var" in Javascript to a C# application which is displaying the webpage containing the Javascript in a Web Browser object. Commented Dec 29, 2012 at 0:36

1 Answer 1

3

You can invoke methods (and thus pass data) in your C# code from JavaScript using Window.external. Try googling for this keyword, more information will come up quickly.

This blog post has a good, simple (WPF-)example how to invoke a C# method from JavaScript using Window.external. Another keyword here is [System.Runtime.InteropServices.ComVisibleAttribute(True)]. You have to mark your handler class with this attribute to be accessible from JavaScript. And finally you tell your WebBrowser control about the handler class via its ObjectForScripting property.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, it seems interesting. Currently we were using anchor hooks to invoke calls and the data passed on the URL (in the query). This seems interesting, especially if the C# can return back data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.