从目标C执行Javascript代码 [英] Executing Javascript Code From Objective C
问题描述
我有一些需要从Objective-C(iPhone)应用程序执行的javascript代码.
I have some javascript code that I need to execute from an objective-c (iPhone) app.
javascript代码需要iPhone应用程序中的某些值.我的意思是,iPhone应用程序( textbox
)中有一个供用户键入其姓名的位置.然后运行的javascript代码将是: alert(name)
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)
其中 name
变量实际上是 textbox.text
如何在不依赖外部Web服务器的情况下从Objective-C做到这一点?
How can I do this from objective-c, without relying on an external webserver?
谢谢!
推荐答案
添加 UIWebView
并使用注入包含JavaScript的
< script>
标记[webview loadHTMLString:html]
Add a UIWebView
and inject a <script>
tag containing the JavaScript using [webview loadHTMLString: html]
这篇关于从目标C执行Javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!