【发布时间】:2011-08-01 19:22:28
【问题描述】:
我正在尝试将本地 css 文件注入完成加载网站(如 google 等)的 UIWebView。
我正在尝试使用 JavaScript,但没有成功。
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *cssPath = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"styles.css"]];
NSURL *baseURL = [NSURL fileURLWithPath:cssPath];
NSString *js = [NSString stringWithFormat:@"var fileref = document.createElement('link');
fileref.setAttribute('rel', 'stylesheet');
fileref.setAttribute('type', 'text/css');
fileref.setAttribute('href', %@);", baseURL];
[webView stringByEvaluatingJavaScriptFromString:js];
}
谢谢,
【问题讨论】:
标签: javascript iphone css ios uiwebview