Can I call javascript directly in WPF without using a browser object

I would like to be able to create an application that uses open layers directly in my WPF application. I found that I can create a browser object and run JavaScript, but I do not need a full browser. Is there any script object that I can use and get around the browser object?

+5
source share
2 answers

You do not need a web browser or WebBrowser control to use JavaScript in the .NET Framework. The .NET Framework has a built-in JavaScript implementation that implements a superset of JavaScript / ECMAScript, as described here and.

To use the NET Framework built into the JavaScript implementation:

  • Add assembly link Microsoft.JScript
  • Use new JScriptCodeProvider().CreateCompiler().CompileAssemblyFromSource(...).CompiledAssemblyto compile JavaScript to assembly
  • Call the code in the compiled assembly as usual (GetType / GetMethod / Invoke)

Note that if your JavaScript code is designed to control the DOM or use other functions of the web browser, you can still use the version of JavaScript for the NET Framework, but you will need to provide the expected objects yourself.

+7
source

WebBrowser WPF javascript

 myWebBrowser.ObjectForScripting =  new HtmlBridge();
0

All Articles