ios 不支持iframe 解决方案

本文介绍了一种在移动设备上优化iframe加载的方法,通过动态调整iframe及其父容器的样式来改善用户体验。该方法特别针对iPad和iPhone等iOS设备进行了优化。

在iframe外层在包一层,通过appendChild()把内容增加到容器中,完整代码如下:

 1 @section Css
 2     {
 3     <link href="@ViewHelper.Content("/Content/css/mobiscroll.css")" rel="stylesheet" type="text/css" />
 4     <link href="@ViewHelper.Content("/Content/css/common.css")" rel="stylesheet" />
 5 }
 6 <style>
 7     .frame {
 8         margin-top: 55px;
 9         padding: 10px;
10         height: 90vh;
11         width: 100vw;
12         border: none;
13     }
14 </style>
15 <div id="iframe-box">
16     <iframe id="ifram" class="frame" width="420" height="330" src="@ViewBag.PathUrl.Replace("http://","https://")"></iframe>
17 </div>
18 @section Js{
19     <script>
20         var ifram = document.getElementById('ifram');
21         if (navigator.userAgent.match(/iPad|iPhone/i)) {
22             var iframe_box = document.getElementById('iframe-box');
23             iframe_box.style.width = 100 + '%';
24             iframe_box.style.overflowX = 'hidden';
25             iframe_box.style.overflowY = 'scroll';
26             iframe_box.style.webkitOverflowScrolling = 'touch';
27             ifram.setAttribute('scrolling', 'no');
28             iframe_box.appendChild(ifram);
29         }
30     </script>
31 }

 

转载于:https://www.cnblogs.com/CandyManPing/p/6886466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值