I have a UIWebView embedded in my view controller like this:
I have an outlet to my web view (_graphTotal
) and I can successfully load the contents of test.html
in it using this:
[_graphTotal loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]isDirectory:NO]]];
I'm now trying to pass data to the web view and haven't had any luck. I have added the <UIWebViewDelegate>
and here's what I'm trying:
NSString *userName = [_graphTotal stringByEvaluatingJavaScriptFromString:@"testFunction()"];
NSLog(@"Web response: %@",userName);
And here are the contents of test.html
in my project:
<html>
<head></head>
<body>
Testing...
<script type="text/javascript">
function testFunction() {
alert("made it!");
return "hi!";
}
</script>
</body>
</html>
I can see "Testing..." in my webView, but I'm not seeing the alert nor the returned "hi!" string.
Any idea what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…