正在运行web.html存储在资源中。
在
web.html,身体
NSString *path = [[NSBundle mainBundle] pathForResource:@"web" ofType:@"html"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:jsCode];
[webView setDelegate:self];
[webView loadHTMLString:jsCode baseURL:nil];
,你应该有onload()
,之后webView
启动将火。
<html> <body> <head>
<script>
function anyFunction(){
window.location='testing123';
}
</script>
</head><body onload="anyFunction();">
</body></html>
从那里,你应该可以抓住“testing123”。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *data = [[[request URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([data isEqualToString:@"testing123"])
NSLog(@"value received");
}
你能发表一些代码吗?也许在'webView'委托? – HelmiB 2012-03-03 13:00:34