首页 > 代码库 > ios 不支持iframe 解决方案

ios 不支持iframe 解决方案

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

 1 @section Css 2     { 3     <link href="http://www.mamicode.com/@ViewHelper.Content("/Content/css/mobiscroll.css")" rel="stylesheet" type="text/css" /> 4     <link href="http://www.mamicode.com/@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="http://www.mamicode.com/@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 }

 

ios 不支持iframe 解决方案