[英]FancyBox with iframe working in Chrome but not working in IE or FireFox
[英]JavaScript Resize iFrame - working in Firefox/IE but not Chrome
根據我的判斷,我被迫使用iframe通過CMS傳遞HTML5內容,而CMS無法自行管理內容。 iframe和主機頁面位於同一個域中,因此我可以很容易地在它們之間進行通信。
iFrame中的內容會動態調整大小(這是一個在線支付頁面,並且包含未正確填寫的字段的確認詳細信息/錯誤消息),我正在使用此JavaScript調整其大小:
function autoResize(id){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
}
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
我正在使用此代碼在主頁中顯示iframe,高度是iframe頁面可以達到的最大大小:
<iframe id="iframe1" height="1550px" frameborder="0" width="100% marginheight="0" src="/something.html" scrolling="no" onload="autoResize('iframe1')"/>
要動態調整頁面元素的大小並滾動,我使用iframe代碼中的onclick事件與父頁面進行通信:
onclick="setTimeout(function(){parent.parent.autoResize('iframe1');},10); window.parent.parent.scrollTo(0,500);"
setTimeout是必需的,因為我有其他腳本在onclick事件上運行,我需要先觸發它們並調整iframe頁面的大小然后告訴主頁調整iframe的大小。
這比我在Firefox和IE11中預期的要好得多,但它在Chrome中不起作用。 任何人對如何在Chrome中使用此功能有任何想法?
我假設它只是針對Chrome的一些調整,但它是早上8:45,我從昨晚9點開始就一直在努力,所以我有點虧。
謝謝,
麥克風
哦,信用到期的信用。 我從StackOverflow帖子中獲得了原始的調整大小代碼(第一個引用塊)。 我只是忘了給鏈接添加書簽!
你的iframe中缺少雙引號是糾正
<iframe id="iframe1" height="1550px" frameborder="0" width="100%" marginheight="0" src="/something.html" scrolling="no" onload="autoResize('iframe1')>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.