本文介绍了使用V8 JavaScript引擎在没有Web视图的情况下执行JS lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在开发一个JavaScript组件,负责向服务器发出请求并将结果分派给UI。通过在JavaScript中执行此操作,我可以在多种类型的UI中使用我的组件:Android应用程序,iOS应用程序,桌面应用程序(QT),Web应用程序......I am developing a JavaScript component which is responsible for making requests to the server and dispatching results to the UI. By doing this in JavaScript, I am able to use my component in several types of UI: Android app, iOS app, desktop app (QT), web app...所有这些UI都实例化了一个Web视图,因此我的组件在UI加载专用URL时启动( webview.load(file://myfirstWebPage.html) )。All these UI have instantiated a web view, so my component is started when the UI loads the dedicated URL (webview.load("file://myfirstWebPage.html")).第一个网页加载所有JavaScript组件,一旦完成,UI就可以向JavaScript组件发出一些请求,这会向服务器,当它有响应时,它将它发送回客户端(UI Android,UI iOS ...)This first web page loads all the JavaScript components, and when it's done, the UI is able to make some requests to the JavaScript component, which makes a request to the server and when it has the response, it dispatches it back to the client (UI Android, UI iOS ...)这个架构工作正常,但我想要知道是否有其他方法加载JavaScript组件而不使用每个客户端上的Web视图?This architecture works fine, but I would like to know if there is another way to load the JavaScript component without using a web view on each client? V8引擎可以帮助我吗?Can the V8 engine help me?推荐答案如果我理解你的问题,你正在寻找一种在许多平台上执行JavaScript的方法(iOS,Android等)不使用WebView。该解决方案将是特定于平台的,因为即使底层WebView实现对于每个平台也是不同的。If I'm understanding your question, you're looking for a way to execute JavaScript across many platforms (iOS, Android, etc.) without the use of a WebView. The solution will be platform-specific, since even the underlying WebView implementations are different for each platform.对于Android,只要设备附带V8,您就可以通过其API创建一个新的V8上下文并使用它来执行您的JavaScript。该设备实际上必须随V8一起提供。 此答案可能会对您有所帮助。For Android, so long as the device ships with V8, you can create a new V8 Context via its API and use that to execute your JavaScript. The device must actually ship with V8. This answer may help you further.对于iOS,使用 JavaScriptCore ,iOS7的最新发展已经允许您加载和运行任意JavaScript代码。 在此处阅读更多内容。For iOS, which uses JavaScriptCore, recent developments in iOS7 have been made to allow you load and run arbitrary JavaScript code. Read more here. 这篇关于使用V8 JavaScript引擎在没有Web视图的情况下执行JS lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 13:34