Can I add some js code to the webview from Unity, and eval them for a result?

Yes, you can add your own javascript code from Unity's C# or UnityScript. Use AddJavaScript method to pass a js string you want to add. Then you can do an EvaluatingJavaScript calling to get the result.

Be careful that the AddJavaScript method is an async action on Android. It could be dangerous if you eval a js right away after you adding one, and it happens to be depending the added one. So, you should wait for some time (generally speaking one update or two) before calling EvaluatingJavaScript. Another solution is do a polling, which means calling EvaluatingJavaScript continuously, until you get a expected result. The best way is implement your complicate js logic directly in the web page, as what we did the demo scene. You can refer to the script reference for more information.

There is no such limit in iOS system, because the AddJavaScript is a sync operation on iOS.

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk