css - 以响应方式将 Bootstrap 网页嵌入到 iframe 中

标签 css twitter-bootstrap iframe responsive-design embed

我正在开发一个 SaaS 应用程序,它本质上是为客户提供一个完整的网页。客户可以访问他们的页面:http://client.myapp.com .但是我想让客户轻松地将此页面嵌入到他们的网站上。目前我只是提供了一个带有样式表的 iframe 嵌入代码来重置 body 标签的边距。

<head>
<style type="text/css">
html { overflow: auto; }
html, body, div, iframe { margin: 0px; padding: 0px; height: 100%; border: none; }
iframe { display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden; }
</style>
</head>

<body>
<iframe id="myapp" name="myapp" src="https://client.myapp.com" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
</body>

但是当他们包含 iframe 时,页面不再响应。在使用 iframe(或您可能建议的任何其他方式)时,如何复制原始网页的响应能力?

最佳答案

所以我找到了两个解决问题的办法:

解决方案一:

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>body { margin: 0px; } .embed-container { position: relative; padding-bottom: 100%; height: 0; overflow: hidden; max-width: 100%; min-height: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style>
</head>
<body>
<div class='embed-container'><iframe src='https://client.myapp.com' style='border:0;'></iframe></div>
</body>

解决方案 2:

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
/* Using http://npr.github.io/responsiveiframe/ */
<script src="jquery.responsiveiframe.js"></script>

<script type='text/javascript'>
$(function() {
  $('iframe').responsiveIframe({xdomain: '*'});
});
</script>

<style>
body {
  margin: 0;
}
</style>
</head>

<body>

<iframe src='https://client.myapp.com' style='border:0; width: 100%; height: 100%;'></iframe>

</body>

到目前为止,它似乎在桌面浏览器(Chrome、Firefox)和我的手机(Android 4)上都运行良好

关于css - 以响应方式将 Bootstrap 网页嵌入到 iframe 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23652242/

相关文章:

javascript - 从数组中填充下拉列表

html - Bootstrap 2.3 网格操作

javascript - JQuery show() 不适用于 IE 10 中的 iframe

javascript - 将 div 添加到 css 多列

python - 如何使用 python 和 beautifulsoup4 循环和抓取多个页面的数据

html - CSS3 : How can I get something that works like "absolute" but isn't?

twitter-bootstrap - 为什么 Twitter Bootstrap Carousel 在第一次切换后停止?

iframe - 如何在 youtube Iframe 上禁用全屏?

javascript - Chrome 开发工具在调试 iframe contentWindow 时崩溃

css - 如何用css实现这样的渐变