1.页面没有加载完走了失败的代理方法(uiwebview didFailLoadWithError -999 error code):
在uiwebview里,如果load一个url还没结束就立即load另一个url,那么就会callback didFailLoadWithError method,error code is -999。solution is 在didFailLoadWithError 里添加下列code
<p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><span style="color: rgb(255, 255, 255);"><strong> </strong></span><strong>if ([error code] != NSURLErrorCancelled) {</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light'; min-height: 13px;"><strong><span style="font-size:14px;"> </span></strong></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><strong> self.failLoadingView = [[SGDefaultView alloc] initWithFrame:self.view.bounds AndY:100 DefaultView:@"no_network_img" AndText:@"Ooops!网络不好..." AndButton:@"刷新"AndBlock:nil];</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><strong> [self.view addSubview:_failLoadingView];</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light'; min-height: 13px;"><strong><span style="font-size:14px;"> </span></strong></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><strong><span style="font-size:14px;"> }</span></strong></p>2.获取网页的标题:
NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
3.webview返回效果处理:
//用苹果自带的返回键按钮处理如下(自定义的返回按钮)
- (void)returnBack:(UIBarButtonItem *)btn
{
if ([self.baseWebView canGoBack]) {
[self.baseWebView goBack];
}else{
[self.view resignFirstResponder];
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark - UIWebViewDelegate
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];;
}
//如果是H5页面里面自带的返回按钮处理如下:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString * requestString = [[request URL] absoluteString];
requestString = [requestString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//获取H5页面里面按钮的操作方法,根据这个进行判断返回是内部的还是push的上一级页面
if ([requestString hasPrefix:@"goback:"]) {
[self.navigationController popViewControllerAnimated:YES];
}else{
[self.baseWebView goBack];
}
return YES;
}