javascript實現(xiàn)框架高度隨內(nèi)容改變的方法
更新時間:2015年07月23日 15:10:28 作者:李榮飛
這篇文章主要介紹了javascript實現(xiàn)框架高度隨內(nèi)容改變的方法,實例分析了通過父頁面及內(nèi)容改變框架高度兩種實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了javascript實現(xiàn)框架高度隨內(nèi)容改變的方法。分享給大家供大家參考。具體如下:
有兩種方法:
一、就是通過父頁面改變
這里要理解框架的兩個屬性 contentWindow 和contentDocument 兩個屬性的意思和window document意思差不多,不同的是contentWindow 所有瀏覽器都支持,contentDocument ie6,7不支持,chrome 也不支持
<iframe onload="change_height()"></iframe>
function change_height(){
var iframe=document.getElementById("iframe_id");
//取得框架元素
var i_height=iframe.contentWindow.document.body.scrollHeight||iframe.contentWindow.document.documentElement.scrollHeight;
//取得框架內(nèi)容的高度
iframe.height=i_height;
//改變
}
二、就是通過內(nèi)容改變
在內(nèi)容頁進(jìn)行
window.onload=function(){
var iframe=parent.document.getElementById("iframe_id");
//取得框架元素
iframe.height=document.body.scrollHeight||document.documentElement.scrollHeight;
//取得框架內(nèi)容的高度并改變
}
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
javascript如何讀寫本地sqlite數(shù)據(jù)庫
這篇文章主要介紹了javascript如何讀寫本地sqlite數(shù)據(jù)庫問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02
javascript中的self和this用法小結(jié)
本篇文章主要是對javascript中的self和this用法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02

