最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Can I invoke javascript directly in WPF without using the browser object - Stack Overflow

programmeradmin1浏览0评论

I would like to be able to make an application that uses open layers directly on my WPF application. I found that I can create a browser object and have that invoke JavaScript, but I don't need a full browser. Is there some scripting object that I can use and bypass the browser object all together?

I would like to be able to make an application that uses open layers directly on my WPF application. I found that I can create a browser object and have that invoke JavaScript, but I don't need a full browser. Is there some scripting object that I can use and bypass the browser object all together?

Share Improve this question asked Aug 13, 2010 at 2:00 PatrickRPatrickR 801 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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

To use NET Framework's built in JavaScript implementation:

  1. Add a reference to the Microsoft.JScript assembly
  2. Use new JScriptCodeProvider().CreateCompiler().CompileAssemblyFromSource(...).CompiledAssembly to pile your JavaScript to an assembly
  3. Invoke code in the piled assembly as usual (GetType/GetMethod/Invoke)

Note that if your JavaScript code is designed to manipulate a DOM or use other features of a web browser, you can still use the NET Framework's version of JavaScript but you will have to provide the expected objects yourself.

Only the WebBrowser in WPF can run javascript

 myWebBrowser.ObjectForScripting =  new HtmlBridge();
发布评论

评论列表(0)

  1. 暂无评论