正在運行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