其中js代碼如下
function reinitIframe(){
var iframe = document.getElementById("mainframe"); //獲得iframe
try{
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; //獲得iframe內文檔的滾動條的高度
var bHeight = iframe.contentWindow.document.body.scrollHeight; //獲得iframe中body的滾動條的高度
var height = Math.max(bHeight, dHeight); //取其中的最大值
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 200); //通過自動調用動態改變iframe的高度,解決了iframe一旦變大不會變小的問題
其中 chrome 瀏覽器 把他當成跨域的iframe,因此必須用http訪問才能解決問題