I need to fill a html webview with variables that I have stored in objective C.
I believe that I need to use:
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"John", firstName];
but not sure what to put there and what my javascript needs to be to implement the passed variables.
here is a little bit of my html to help get an idea:
<ul><li><span>First Name:</span> first name needs to go here</li>
<li><span>Last Name:</span> last name needs to go here</li>
Updated code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"idcard" ofType:@"html"]isDirectory:NO]]];
}
-(void)viewDidAppear:(BOOL)animated
{
NSString *str = @"John";
NSString *script = [NSString stringWithFormat:@"myFunc('%@')", str];
[self.webView stringByEvaluatingJavaScriptFromString:script];
}
Update 2: javascript/html:
<ul><li><span>Policy Number:</span>
<script> function myFunc(str)
{
document.write(str) }
</script>