html程式碼在網頁端顯示正常,在手機端呼叫,造成字型、圖片有誤差解決方式
htmlStr = [NSStringstringWithFormat:@"<!DOCTYPE html PUBLIC '-//WAPFORUM//DTD XHTML Mobile 1.0//EN' 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'>"
"<head>"
"<style type=\"text/css\">"
"body {font-size:15px;}"
"</style>"
"</head>"
"<body>"
"<script type='text/javascript'>"
"window.onload = function(){"
"var $img = document.getElementsByTagName('img');"
"for(var p in $img){"
" $img[p].style.width = '90%%';"
"$img[p].style.height ='auto'"
"}"
"}"
"</script>%@"
"</body>"
"</html>"
self.webView.autoresizesSubviews = YES;//自動調整大小
self.webView.scalesPageToFit = YES;
self.webView.scrollView.delegate = self;
self.webView.delegate = self;
[self.webViewloadHTMLString:htmlStrbaseURL:nil];
註釋:1)<!DOCTYPE html PUBLIC '-//WAPFORUM//DTD XHTML Mobile 1.0//EN' 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>"
將html程式碼標註為手機端使用
2)下部分程式碼是針對html程式碼裡的圖片做處理:" $img[p].style.width = '90%%';" ,90代表佔螢幕寬度90%
3)Str,後臺傳來的html程式碼:"</script>%@"