如何在移动浏览器的iframe中保留响应式设计?

编程入门 行业动态 更新时间:2024-10-25 02:20:18
本文介绍了如何在移动浏览器的iframe中保留响应式设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在iframe中加载响应式设计网站作为我网站的网页之一。

I would like to load a responsive design website in an iframe as one of my website's pages. However, when it's loaded in the iframe, the site loses its responsiveness.

使用Mashable作为示例(这是内置响应式设计) - 我的代码看起来像这:

Using Mashable as an example (which is built in responsive design)- my code looks like this:

<body> <style> body {width:100%;height:100%;margin:0;overflow:hidden;background-color:#252525;} #iframe {position:absolute;left:0px;top:0px;} </style> <iframe id="iframe" name="iframe1" frameborder="0" width="100%" height="100%" src="mashable"></iframe> </body>

如果您在手机上访问mashable,则会看到响应式设计。但是,如果您在手机上访问上面的页面,mashable的响应设计无法正常工作。

If you go to mashable on your phone, you'll see the responsive design in action. However, if you visit the page above on your phone, mashable's responsive design isn't functioning.

有人知道如何在div中加载网页,响应式设计?

Does anyone know how to load a web page in a div and keep its responsive design?

提前感谢!

推荐答案

strong>元标记移动到页面的顶部,以告诉移动浏览器不缩放页面。 桌面上的Safari已默认尊重iframe内容的响应式设计。

Add the meta tag "viewport" to the head of your page to tell the mobile browser not scale the page. Safari on the desktop already respects the responsive design of the iframe content by default.

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0 maximum-scale=1.0" />

打开此JSBin链接,以便测试 元标记和以下内容链接 元标记。要编辑,请打开此 JSBin页面。

Open this JSBin link on your mobile to test with the meta tag and the following link without the meta tag. To edit open this JSBin page.

注意。已在iPhone 5(iOS6)和Safari 6上测试。

NB. Tested on iPhone 5 (iOS6) and Safari 6.

更多推荐

如何在移动浏览器的iframe中保留响应式设计?

本文发布于:2023-11-01 20:31:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   如何在   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!