UIWebView获得内容的高-作出自适应高的UIWebView + WebView中点击链接返回
1 - (void)webViewDidFinishLoad:(UIWebView *)webView 2 { 3 NSString *height_str= [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"]; 4 int height = [height_str intValue]; 5 webView.frame = CGRectMake(0,0,320,height); 6 NSLog(@"height: %@", [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"]); 7 }
点击返回
1 //你是想点击链接实现页面的返回 2 3 [self.navigationController popViewControllerAnimated:YES]; 4 5 //还是想点击上面的返回键,回到网页的上一页 6 7 8 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 9 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 10 // 下一个界面的返回按钮 11 UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; 12 temporaryBarButtonItem.title = @"back"; 13 temporaryBarButtonItem.target = self; 14 temporaryBarButtonItem.action = @selector(back:); 15 self.navigationItem.backBarButtonItem = temporaryBarButtonItem; 16 17 } 18 19 return self; 20 21 } 22 23 24 -(void) back 25 { 26 if ([webView canGoBack]) { 27 [webView goBack]; 28 } 29 else 30 { 31 [self.navigationController popViewControllerAnimated:YES]; 32 33 } 34 } 35 36 //补充上面的,你要想点击链接返回 37 - (void)webViewDidFinishLoad:(UIWebView *)webView { 38 39 if ([webView.request.URL isEqual: @"你的链接地址"]) { 40 [self.navigationController popViewControllerAnimated:YES]; 41 } 42 43 }