Executing Javascript Code From Objective C

北慕城南 提交于 2021-01-29 13:39:29

问题


I have some javascript code that I need to execute from an objective-c (iPhone) app.

The javascript code needs some of the values from the iPhone app. What I mean is, there is a spot in the iPhone app (a textbox) for a user to type their name. Then the javascript code that runs will be: alert(name)

where the name variable is really textbox.text

How can I do this from objective-c, without relying on an external webserver?

Thank you!


回答1:


Add a UIWebView and inject a <script> tag containing the JavaScript using [webview loadHTMLString: html]



来源:https://stackoverflow.com/questions/7922961/executing-javascript-code-from-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!