iOS webview注入JS
- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *js = @"function imgAutoFit() { \ var imgs = document.getElementsByTagName('img'); \ for (var i = 0; i < imgs.length; ++i) {\ var img = imgs[i]; \ img.style.maxWidth = %f; \ } \ }"; js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20]; [webView stringByEvaluatingJavaScriptFromString:js]; [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"]; }
目前没用到,备份一下
原帖地址:http://ios.jobbole.com/84216/