开发者

iOS UIWebView html builder?

With a UIWeb view, how do I build html? For instance, I have some header html. But then I want to inject a javascript and pass data into it. After I insert the javascript, I want to append the rest of the html that is located in a .html file.

The javascript would be something like this:

<script type="text/javascript"> 
var script_object = myNSStringValue1;
var volunteer_name = myNSStringValue2;
</开发者_如何学运维script>

Thoughts?


in uiwebview we have a method loadHtml use this one


In objective C you can use this to inject javascript:

    NSString* jsCallback = [NSString stringWithFormat:@"yourVeryOwnJavascriptFunction('%@,%@');",string1,string2];
[ self.webView stringByEvaluatingJavaScriptFromString:jsCallback];

Calling this would execute the javascript function. In the javascript function you could set text fields or change any html with the passed parameters of string1, and string2. Your javascript would look like this.

    yourVeryOwnJavascriptFunction(string1,string2)
{
 //custom javascript goes here. 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜