How to pass large amount of html content stored in NSString from objective c to javascript in UIWebView
Replies
First up, if you’re using UIWebView you should consider making the switch to WKWebView; it’s the future of web views on our platforms.
Second, define “large” in this context? Hundreds of KiB? MiB? Tens of MiB?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks for your information.
The size of html content that needs to be passed from obj-c to js is around 40KB.
Oh wow, much smaller than I expected. At that size I’d just wrap the HTML in a JavaScript string and pass that in to the web view via
-stringByEvaluatingJavaScriptFromString:
.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you.
Could you please give me a sample on how to wrap the HTML in a JavaScript string?
I've tried in the following way to send NSString variable conte to pass to the javascript function otverse(t)
Length of conte : 4223
in objective-c
NSString *fun = [NSString stringWithFormat:@"otverse(['%@'])",conte];
[self.webView stringByEvaluatingJavaScriptFromString:fun];
in javascript from html file
function otverse(t)
{
alert("Result from obj-c " + t);
}
But the function otverse is not called.
Further if i call the javascript function otverse with small string, it is invoked.
Could you help me to pass string of length more than 1000 to javascript from obj-c.
Thanks in advance.