- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//修改頁面meta值
NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", webView.frame.size.width];
[webView stringByEvaluatingJavaScriptFromString:meta];
}
//增加UTF-8編碼
-
[webView stringByEvaluatingJavaScriptFromString: @"var tagHead =document.documentElement.firstChild;"
"var tagMeta = document.createElement(\"meta\");"
"tagMeta.setAttribute(\"http-equiv\", \"Content-Type\");" "tagMeta.setAttribute(\"content\", \"text/html; charset=utf-8\");"
"var tagHeadAdd = tagHead.appendChild(tagMeta);"];
[webView stringByEvaluatingJavaScriptFromString:
@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function ResizeImages() { "
"var myimg,oldwidth;"
"var maxwidth=380;" //頁面寬度
"for(i=0;i <document.images.length;i++){"
"myimg = document.images[i];"
"if(myimg.width > maxwidth){"
"oldwidth = myimg.width;"
"myimg.width = maxwidth;"
"myimg.height = myimg.height * (maxwidth/oldwidth);"
"}"
"}"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
[webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
沒有留言:
張貼留言