[英]How to get iframe contents height when src is base64 encoded?
這是我要動態顯示內容的iframe。
<iframe onload='resize()' id='ifr' src='data:text/html;charset=utf-8;base64,Encoded text here' width=100% height=400px></iframe>
我嘗試過這樣的事情..但是高度總是返回0
function resize() {
$('#ifr').height($('#ifr').contents().height());
}
這是jsfiddle ..
$('iframe')會為您提供文檔中的所有iframe,因此您應該給框架賦予id並像$('#MYiframe')一樣使用它,或者從jquert返回的值中獲取第一個元素。
function resize() {
$('iframe')[0].height($('iframe')[0].contents().height());
}
而且我在SO上也找到了用於調整內容iframe大小的方法。
iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
iFrame.height = iFrame.contentWindow.document.body.scrollHeight;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.