• 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 } 
     
     
  • 相关阅读:
    力扣(LeetCode)验证回文串 个人题解(C++)
    力扣(LeetCode)平方数之和 个人题解
    Exclusive Access 2 UVA
    C语言中指针*p[N], (*P)[N]的区别
    2018年蓝桥杯国赛比赛心得
    2018acm/icpc西安邀请赛比赛心得
    [最小割]Cable TV Network UVA
    Tree Reconstruction UVA
    Twenty Questions UVA
    python中的enumerate 函数(编号的实现方式)
  • 原文地址:https://www.cnblogs.com/lxllanou/p/4048505.html
Copyright © 2020-2023  润新知