UIWebView执行JS语句

示例网页:

http://m.dianping.com/tuan/deal/moreinfo/11507109

移除该网页的返回按钮, 购买链接, 最底部的友情链接

代码:

 NSMutableString *js = [NSMutableString string];

// 删除返回按钮

[js appendString:@"var backBtn = document.getElementsByClassName('back back-gray')[0];"];

[js appendString:@"backBtn.parentNode.removeChild(backBtn);"];

// 删除顶部的购买

[js appendString:@"var box = document.getElementsByClassName('cost-box')[0];"];

[js appendString:@"box.parentNode.removeChild(box);"];

// 删除底部的购买

[js appendString:@"var buyNow = document.getElementsByClassName('buy-now')[0];"];

[js appendString:@"buyNow.parentNode.removeChild(buyNow);"];

// 删除友情链接

[js appendString:@"var footer = document.getElementsByClassName('footer')[0];"];

[js appendString:@"footer.parentNode.removeChild(footer);"];

[webView stringByEvaluatingJavaScriptFromString:js];

上一篇:一个完整的数据分析流程


下一篇:异步网络消息处理框架