首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

ios UIWebView缴获html并修改便签内容

2012-08-02 
ios UIWebView截获html并修改便签内容需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左

ios UIWebView截获html并修改便签内容
需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果;
方法:通过js截获UIWebView中的html,然后修改html标签内容;
实例代码:
服务器端html


这样显示的结果网页的最小宽度会是device-width;但有时候不需要这个宽度,就需要修改width=device-width为width=myWidth;
客户端代码
- (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];}

这样问题就可以解决了
其他html属性重载和此方法类似;
参考网址:
(stringByEvaluatingJavaScriptFromString的使用方法)http://www.uml.org.cn/mobiledev/201108181.asp  
( iphone 获取UIWebView内Html方法)http://blog.csdn.net/diyagoanyhacker/article/details/6564897
(IOS UIWebView引用外部CSS样式)http://hi.baidu.com/jwq359699768/item/780879e5c98bfb3e4ddcaf22

热点排行