UIWebView 页面处理

来源:互联网 发布:软件项目经理面试 编辑:程序博客网 时间:2024/06/05 14:06

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    // 定义JS字符串

    NSString *script = [NSStringstringWithFormat:@"var script = document.createElement('script');"

                        "script.type = 'text/javascript';"

                        "script.text = \"function ResizeImages() { "

                        "var myimg;"

                        "var maxwidth=%f;"//屏幕宽度

                        "for(i=0;i <document.images.length;i++){"

                        "myimg = document.images[i];"

                        "myimg.height = maxwidth / (myimg.width/myimg.height);"

                        "myimg.width = maxwidth;"

                        "}"

                        "}\";"

                        "document.getElementsByTagName('p')[0].appendChild(script);", [UIScreenmainScreen].bounds.size.width];

    

    // 添加JS

    [webView stringByEvaluatingJavaScriptFromString:script];

    // 添加调用JS执行的语句

    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];

}


原创粉丝点击