【发布时间】:2016-06-20 08:49:10
【问题描述】:
在标题中我有以下 jQuery 代码:
<script>
$(function(){
var iFrames = $('iframe');
function iResize() {
for (var i = 0, j = iFrames.length; i < j; i++) {
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
}
if ($.browser.safari || $.browser.opera) {
iFrames.load(function(){
setTimeout(iResize, 0);
});
for (var i = 0, j = iFrames.length; i < j; i++) {
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
} else {
iFrames.load(function() {
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
});
}
});
</script>
嵌入看起来像这样:
<div id="appointy">
<iframe src="//hfxtutoring.appointy.com/?isGadget=1" class="iframe" scrolling="no" frameborder="0" allowtransparency="true" style="text-align: center; -webkit-overflow-scrolling: touch; overflow: auto;">
</iframe>
</div>
CSS 是这样的:
/* to ensure proper scrolling and overflow handling on mobile devices, put this styling in a div wrapper around the iframe because it's unreliable in css: -webkit-overflow-scrolling: touch; overflow: auto; */
.iframe
{
border: none;
width: 100%;
margin-right: 10px;
padding: 0;
border: 1px
}
我想要的是 iFrame 根据内容高度调整大小,而不是设置高度。我不完全明白如何让它像this example 一样工作。
【问题讨论】:
-
无法在跨域 iframe 内访问
-
哦。有没有办法使这项工作?
-
你可以试试iframe resizer
-
我无法访问托管 iFrame 的页面以插入该代码。它是第 3 方网站。 (预约),我只能访问我的页面。
-
小心浏览器对 CSS 函数的支持,先生。
标签: javascript jquery iframe size