我嘗試從JavaScript使用IOS調用函數,但仍然無法幫助我請!UIWebView 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];
}
我也試試這一個,但仍然沒有工作。如果我有什麼問題請告訴我
什麼是子視圖?它是一個UIView嗎? – GenieWanted
哦抱歉// subView是UIwebview。 – Kabitis
我已經嘗試在' - (void)webViewDidFinishLoad:(UIWebView *)webView' T-T – Kabitis