[英]UIWebView javascript with IOS Issue
我嘗試從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];
}
我也嘗試了這個,但仍然無法正常工作。 如果我做錯了,請告訴我
請確保subView是UIWebView對象,並且還需要在shouldStartLoadWithRequest
方法中返回YES
或NO
。 還有另一個解決方案-使用模擬器或設備打開Safari調試器,然后在控制台中手動檢查此功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.