我尝试从javascript使用IOS调用函数但仍然无法正常帮助我!
这个javascript
function geturl(getdata) {
// document.getElementById('test1').src = '';
alert(getdata);
}
和IOS代码
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
NSURL *URL = [inRequest URL];
NSString *stringURL = [NSString stringWithFormat:@"%@",URL];
NSString *urlString = inRequest.URL.absoluteString;
NSString * getdata = @"come please";
NSString * sendBack = [NSString stringWithFormat:@"geturl('%@')",getdata];
[subView stringByEvaluatingJavaScriptFromString:sendBack];// subView is UIWebview
return YES;
}
我尝试使用这样但数据不警报我不知道发生了什么事请帮助我!!
-(void)webViewDidFinishLoad:(UIWebView *)webView{
if (loadingPage < [book count]) {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:loadingPage] ofType:@"html" inDirectory:@""]];
[[scrollView.subviews objectAtIndex:loadingPage] loadRequest:[NSURLRequest requestWithURL:url]];
[[scrollView.subviews objectAtIndex:loadingPage] setHidden:NO];
loadingPage++;
subView.scrollView.bounces = NO;
[[subView scrollView] setBounces: NO];
}
NSString * getdata = @"come please";
NSString * sendBack = [NSString stringWithFormat:@"geturl('%@')",getdata];
[subView stringByEvaluatingJavaScriptFromString:sendBack];
}
我也试过这个,但仍然无法正常工作。如果我出错了,请告诉我
答案 0 :(得分:1)
请确保subView是UIWebView对象,并且您需要在YES
方法中返回NO
或shouldStartLoadWithRequest
。
还有一个小解决方案 - 使用模拟器或设备打开safari调试器,并在控制台中手动检查此功能