作者:额哦哦额llo | 来源:互联网 | 2023-09-06 14:15
最近在做一些hybird框架的项目,对于embed的UIWebView,其宽度一般由Native app 指定,对于HTML页面
其中若是width指定为device-width,那么embed的UIWebView的宽不应设置小于device-width的值,如ipad的宽为768
在webView中查看HTML页面源代码
- (void)webViewDidFinishLoad:(UIWebView *)webView_ {
NSString *jsToGetHTMLSource = @"document.getElementsByTagName('html')[0].innerHTML";
NSString *HTMLSource = [webView_ stringByEvaluatingJavascriptFromString:jsToGetHTMLSource];
NSLog(@"%@",HTMLSource);
}
在webView中调整HTML页面宽度
- (void)adjustPageWidth:(UIWebView *)webView_ {
NSString *widthStr = [NSString stringWithFormat:@"%f",webView_.frame.size.width];
NSString * strJS = [NSString stringWithFormat:@"function adjustPageWidth(){var metas = document.getElementsByTagName(\"meta\");var strMeta=new String();var strTemp;for(var i=0;i
在webViewDidFinishLoad中调用调整页面宽度函数
- (void)webViewDidFinishLoad:(UIWebView *)webView_ {
DebugLog(@"%@",NSStringFromSelector(_cmd));
[self adjustPageWidth:webView_];
}