惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
Recent Announcements
Recent Announcements
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
T
Troy Hunt's Blog
F
Fortinet All Blogs
Webroot Blog
Webroot Blog
S
Secure Thoughts
D
Docker
Attack and Defense Labs
Attack and Defense Labs
博客园 - 叶小钗
H
Heimdal Security Blog
S
Security Affairs
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
T
Tenable Blog
I
InfoQ
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
IT之家
IT之家
Vercel News
Vercel News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
博客园 - 聂微东
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
Latest news
Latest news
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Cloudbric
Cloudbric
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
N
Netflix TechBlog - Medium
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
C
Check Point Blog
Recorded Future
Recorded Future
Jina AI
Jina AI

博客园 - 飞花雪月

ASP.NET Core-wwwroot文件夹 ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误) 两步验证Authy时间同步问题 您的项目引用了最新实体框架;但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mysql的技巧 教你如何调用百度编辑器ueditor的上传图片、上传文件等模块 Easyui Tree方法扩展 - getLevel(获取节点级别) HTML5添加 video 视频标签后仍然无法播放的解决方法 IIS添加MIEI类型 ASP.NET性能优化之减少请求 ASP.NET中获取当日,当周,当月,当年的日期 Convert.ToInt32()与int.Parse()的区别 C#/JS 获取二维数组组合 【转】浅析Sql Server参数化查询 【转】Sql Server参数化查询之where in和like实现之xml和DataTable传参 【转】Sql Server参数化查询之where in和like实现详解 推薦使用 Microsoft Anti-Cross Site Scripting Library V3.0 推薦使用 Microsoft Anti-Cross Site Scripting Library v3.1 IIS中ASP.NET安全配置 好用的SQLSERVER数据库自动备份工具SQLBackupAndFTP(功能全面) 从WEB SERVICE 上返回大数据量的DATASET
iframe在ipad safari的显示
飞花雪月 · 2014-10-14 · via 博客园 - 飞花雪月

今 天要在web中嵌套一个网址或本地HTML,用到了iframe,在电脑上设置scrolling=‘auto’,宽度高度,会有滚动条出现。而在 ipad上会全部显示整个网页的宽度高度。scrolling属性无效。原来在html5中的iframe已经只有剩下src的属性。 
但是若设置scrolling=‘no’.还是会生效的。页面只显示定义的高度和宽度的大小。设置overflow:hidden都没用。 

怎么让ipad safari 中的iframe的内容在固定大小中可滚动? 

网上说要用seamless属性。直接写个seamless。但是这个属性ipad的safari不支持。chrome是支持的。 

IE6 – Windows: no support 
IE7 – Windows: no support 
IE8 – Windows – Windows: no support 
IE9 beta – Windows: no support 
Firefox 3.6 – Windows: no support 
Firefox 3.6 – OSX: no support 
Firefox 4.0 – beta Windows: no support 
Firefox 4.0 – beta OSX: no support 
Safari OSX: no support 
Chrome 7 – Windows: no support 
Chrome 7 – Windows: no support 
Chrome 9 – OSX: no support 
Opera 11 – OSX: no support 

测试例子: 
http://www.maxdesign.com.au/jobs/example-seamless/ 

所以以上方法都无法解决ipad safari中iframe滚动的问题。 

解决办法: 
在iframe外加一层div,设置样式-webkit-overflow-scrolling:touch; overflow: scroll; 
让超出div的内容可以通过touch来滚动。 

另外,如果iframe的src不是网址,而是本地的html,则需要给HTML的DOM添加监听事件,让html的body可以监听到touch事件,让嵌套的html也可以滚动。

    var toScrollFrame = function(iFrame, mask) {  
                        if (!navigator.userAgent.match(/iPad|iPhone/i))  
                            return false;  
                        //do nothing if not iOS devie  
      
                        var mouseY = 0;  
                        var mouseX = 0;  
                        jQuery(iFrame).ready(function() {//wait for iFrame to load  
                            //remeber initial drag motition  
                            jQuery(iFrame).contents()[0].body.addEventListener('touchstart', function(e) {  
                                mouseY = e.targetTouches[0].pageY;  
                                mouseX = e.targetTouches[0].pageX;  
                            });  
      
                            //update scroll position based on initial drag position  
                            jQuery(iFrame).contents()[0].body.addEventListener('touchmove', function(e) {  
                                e.preventDefault();  
                                //prevent whole page dragging  
      
                                var box = jQuery(mask);  
                                box.scrollLeft(box.scrollLeft() + mouseX - e.targetTouches[0].pageX);  
                                box.scrollTop(box.scrollTop() + mouseY - e.targetTouches[0].pageY);  
                                //mouseX and mouseY don't need periodic updating, because the current position  
                                //of the mouse relative to th iFrame changes as the mask scrolls it.  
                            });  
                        });  
      
                        return true;  
                    };  
      
                    toScrollFrame('.myFrame', '.myMask');  

最终代码

    <!DOCTYPE html>  
    <html>  
        <head>  
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
            <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">  
            <meta name="apple-mobile-web-app-capable" content="yes">  
            <meta name="apple-mobile-web-app-status-bar-style" content="black">  
            <title>wrapScroller demo</title>  
            <link rel="stylesheet" href="../style/wrapScroller.css" type="text/css" media="screen" />  
            <script type="text/javascript" src="../jquery-1.8.0.min.js"></script>  
            <script type="text/javascript">  
                  
            </script>  
        </head>  
        <body style="background: #ccc;">  
            <div>  
                HEADER - use 2 fingers to scroll contents:  
            </div>  
            <div id="scrollee" style="width:300px;height:300px;-webkit-overflow-scrolling:touch; overflow: scroll;">  
                <iframe id="object" height="90%" width="100%" type="text/html" src="http://en.wikipedia.org/"></iframe>  
            </div>  
        </body>  
    </html>  

参考: 
http://stackoverflow.com/questions/6139564/iframe-size-on-ipad 
http://jsfiddle.net/CobaltBlueDW/zHR8s/ 
http://stackoverflow.com/questions/4804604/html5-iframe-seamless-attribute