今 天要在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

 

iframe在ipad safari的显示的更多相关文章

  1. iframe in ipad safari

    http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebconten ...

  2. Ipad Safari iframe cookie 当浏览器默认禁用第三方COOKIE

    前一阵子,我们发现高版本的Safari中默认会阻止第三方cookie,如下图所示. 问题 什么是第三方cookie呢?在访问一个网站A时,网站A算作第一方,如果网站A中引用了另一个网站X(网站X的域名 ...

  3. 轻松进行iPad Safari设置

    推荐 通过iPad Safari设置,iPad中的Safari可以让我们看到我们想看的影片.动画和Web应用程序,关闭部分内容以保护我们的隐私安全和设备安全,至于如何进行iPad Safari设置,下 ...

  4. ipad safari 滚动(overflow)解决方案

    项目需要放到ipad应用了,发现有一个奇怪的问题,就是我div是设置滚动属性的,在pc上面的各个浏览器页面变小时,会出现滚动条,可是是ipad的safari,则不会滚动,开始以为是div的问题 但发现 ...

  5. Easyui弹出窗体在iframe的父级页面显示

    今天做EasyUI学习的预到了一个这样的问题:通过iframe加载的一个页面在调用$.messager.alert();这个方法后只能在iframe中显示alert效果而不是在全局的页面上显示这并不我 ...

  6. IE下iframe不能正常加载,显示空白

    下午帮忙看了一个web问题,index.html中嵌入<iframe>来加载同文件目录下的一个页面,在多个浏览器下测试,发现IE浏览器中会出现问题,<iframe>不能正常加载 ...

  7. 关于iPad上模态显示视图中的UITextField,UITextView在输入完成后无法回收键盘的问题解决。

    在iPad开发过程中遇到一个问题,UITextField 存在由UIModalPresentationFormSheet 弹出的带导航条的视图控制器中时,调用 resignFirstResponder ...

  8. iframe 实现网页本页显示

    <el-dialog title="" :visible.sync="dialogVisible"> <iframe src="ht ...

  9. jqGrid在IE中使用iframe嵌套,页码条不显示问题

    在网页顶部加: 红色部分必须是:XHTML1.0

随机推荐

  1. JAVA基础学习day20--IO流二-缓冲流、字节流

    一.缓冲流 1.1.字符流的缓冲区 缓冲区的出现是为了提高IO的读写效率 对应类 BufferedReader BufferedWriter 缓冲区要结合流才可以使用 在流的基础上对流的功能进行了增强 ...

  2. [Eclipse配置] Eclipse代码中显示空白字符(空格,TAB和回车)的方法

    在代码页面点击右键进入 Preferences --> General --> Editors --> Text Editors. 在 Show whitespace charact ...

  3. Effective Java 08 Obey the general contract when overriding equals

    When it's the case that each instance of the class is equal to only itself. 1. Each instance of the ...

  4. Effective Java 31 Use instance fields instead of ordinals

    Principle Never derive a value associated with an enum from its ordinal; store it in an instance fie ...

  5. JavaScript Patterns 3.5 JSON

    JSON: JavaScript Object Notation {"name": "value", "some": [1, 2, 3]}  ...

  6. 深入剖析jsonp跨域原理

    在项目中遇到一个jsonp跨域的问题,于是仔细的研究了一番jsonp跨域的原理.搞明白了一些以前不是很懂的地方,比如: 1)jsonp跨域只能是get请求,而不能是post请求: 2)jsonp跨域的 ...

  7. poj 3237 Tree [LCA] (树链剖分)

    poj 3237 tree inline : 1. inline 定义的类的内联函数,函数的代码被放入符号表中,在使用时直接进行替换,(像宏一样展开),没有了调用的开销,效率也很高. 2. 很明显,类 ...

  8. HTTP Content-type

    文件扩展名 Content-Type 文件扩展名      Content-Type .* application/octet-stream .tif image/tiff .001 applicat ...

  9. 20150912华为机考2之"输入一段字符串(英文),将每个单词首字母大写后输出"

    还有其他一些(隐性)要求(要不然无法通过测试): .如果首字母已经大写,则不用变 .不是英文字母的不变 e.g. Input: hello world! this is _Ljj speaking! ...

  10. Excel scientific notation issue

        This is a known issue, you can find more in internet. Excel will treat text(can display with num ...