iOS开辟 - 应用js去除webview广告

找到要掏出内容要领:
浏览器设置 -> 更多东西 -> 开发者东西 -> 手机形式(左下角 手机按钮)
点击手机图标左侧谁人搜刮框 -> 然后点击你要隐蔽的控件
挑选到你要挑选到的控件 -> 然后左下角代码就被选中了.
个中右下角中是这个控件对应的css代码,在个中增加一行display:none,这时候这个选中的控件就被隐蔽起来了.然则我们重要经由过程javascript去操纵这个控件
《iOS开辟 - 应用js去除webview广告》

《iOS开辟 - 应用js去除webview广告》

末了代码以下:

//
//  MainViewController.m
//  webview
//
//  Created by ??? on 15/11/24.
//  Copyright © 2015年 ???. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()<UIWebViewDelegate>

@property (nonatomic,strong)UIWebView *webView;


@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self webView];
}

- (UIWebView *)webView{
    if (!_webView) {
        NSString *urlStr = @"http://group.haodou.com/topic-327282.html";
        
        self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
        self.webView.delegate = self;
        self.webView.backgroundColor = [UIColor redColor];
        [self.view addSubview:_webView];
        
        NSURL *url=[NSURL URLWithString:urlStr];
        NSURLRequest *request=[[NSURLRequest alloc] initWithURL:url];
        [self.webView loadRequest:request];
    }
    return _webView;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('main_mu_bar')[0].style.display = 'NONE'"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

编辑笔墨要领

    原文作者:Baaaan
    原文地址: https://segmentfault.com/a/1190000004040813
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞