这是 webview 的实现:
_webView = [[UIWebView alloc]init];
_webView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT + 45);
_webView.scalesPageToFit = YES;
_webView.delegate = self;
_webView.userInteractionEnabled = YES;
[self.view addSubview:_webView];
NSURL *url = [[NSURL alloc]initWithString:@"http://m.weather.com.cn/mweather/101280601.shtml"];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
[_webView loadRequest:request];
这是 webview 的代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSMutableString *js1 = [NSMutableString string];
// 0.删除顶部的导航条
[js1 appendString:@"var header = document.getElementsByClassName('head')[0];"];
[js1 appendString:@"header.parentNode.removeChild(header);"];
// apostertop
[js1 appendString:@"var apostertop = document.getElementsByClassName('apostertop')[0];"];
[js1 appendString:@"apostertop.parentNode.removeChild(apostertop);"];
[js1 appendString:@"var news = document.getElementsByClassName('news');"];
[js1 appendString:@"news.parentNode.removeChild(news);"];
[js1 appendString:@"var ad = document.getElementsByClassName('ad');"];
[js1 appendString:@"ad.parentNode.removeChild(ad);"];
[js1 appendString:@"var life = document.getElementsByClassName('life');"];
[js1 appendString:@"life.parentNode.removeChild(life);"];
//zs
[js1 appendString:@"var zs = document.getElementsByClassName('zs');"];
[js1 appendString:@"zs.parentNode.removeChild(zs);"];
//footer
[js1 appendString:@"var footer = document.getElementsByClassName('footer');"];
[js1 appendString:@"footer.parentNode.removeChild(footer);"];
[webView stringByEvaluatingJavaScriptFromString:js1];
}
问题来了,执行后,显示上没有任何变化,求大神指教!
1
doublleft 2015-11-20 11:25:58 +08:00
是不是取出的 nodelist 没加下标
|
3
lfflyers OP 先自顶一下~~
|
4
black 2015-11-20 11:39:57 +08:00
removeChild 参数一会儿传 node ,一会儿传 nodes 是要闹哪样...
|
5
finian 2015-11-20 11:46:09 +08:00
题外话, JS 就不能写在一个字符串里吗? 现在这分散的语句看起来和维护起来都很蛋疼
|
6
finian 2015-11-20 11:47:16 +08:00
可以用 Safari 调试一下,执行你的 JS ,看哪些生效哪些不生效
|
7
doublleft 2015-11-20 12:13:55 +08:00
stringByEvaluatingJavaScriptFromString 可以先引入 js 文件,然后再执行的,方便定位一些
|
11
lfflyers OP 问题,蛋疼,第一条的 class 写错后,后面的都不执行了
|