Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  0] [ 2]  / answers: 1 / hits: 15905  / 13 Years ago, tue, november 29, 2011, 12:00:00

I have a webpage loaded in a UIWebView, and a javascript function of the page needs to data from native iOs app, a NSString. How can a Js function access the data in native app?



Thanks,



lvreiny


More From » ios

 Answers
17

You can execute JavaScript in your UIWebView from Obj-C. Simply call [webView stringByEvaluatingJavaScriptFromString:@myJavaScript];.



I could imagine a setup like this:



Webpage



<html>
<head>
<script type=text/javascript>
function callmeFromObjC(para1) {
// do something
alert(para1);
}
</script>
</head>
<body>
</body>
</html>


Objective-C



NSString *myParameter = @myParameter;
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@callmeFromObjC('%@'), myParameter]];

[#88858] Sunday, November 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;