以下是iFrame in question。即使使用jQuery腳本,iFrame也不會擴展到全部內容高度
在標題中,我有以下的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 – charlietfl
哦。無論如何做這項工作? – NictraSavios
您可以嘗試[iframe resizer](https://github.com/davidjbradshaw/iframe-resizer) –