1

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?

2 Answers 2

1

in uiwebview we have a method loadHtml use this one

Sign up to request clarification or add additional context in comments.

1 Comment

Ron, do you know how I would go about appending html in a local file to the header string? Or do I have to paste the entire body html file into my string?
1

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. 
}

1 Comment

I would love to see more sample code showing how to do this. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.