|
我在作一個iframe自動調(diào)整高度時,被嵌入的頁面commit.ASP的代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>的相關(guān)評論</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body bgColor="transparent" onload="zoomiframe();">
</body>
</html>
<script language=Javascript>
<!--框架頁自動調(diào)整尺寸-->
function zoomiframe()
{
parent.document.getElementById("comment_load").style.height=document.documentElement.scrollHeight;
}
</script>
然后在另外的頁面插入其它代碼,將這頁嵌入到其它頁面
<iframe src="comment.ASP?classid=2&id=12" allowtransparency="true" name="comment_load" width="540" height="288" marginwidth="0" marginheight="0" align="middle" scrolling="no" frameborder="0"></iframe>
但是沒有效果,iframe不能按照內(nèi)容自動調(diào)高度。
后來我在zoomiframe()加入了一句alert(document.body.scrollHeight);。彈出來的值為0,但如果直接運(yùn)行COMMIT。ASP彈出的高度卻與內(nèi)容相符。
實在搞不明白那里有沖途。我以前這樣作可以,不知道論壇上有沒有那個遇過這種問題。
謝謝!
復(fù)制代碼 代碼如下:
parent.document.all("comment_load").style.height=document.body.scrollHeight||document.documentElement.scrollHeight;
試了一下,應(yīng)該是沒什么問題的
<script type="text/Javascript">
<!--
onload=function()
{
parent.document.getElementById('ac').style.height="200px";
}
//-->
</script>
<iframe src="comment.ASP?classid=2&id=12" allowtransparency="true" name="comment_load" width="540" height="288" marginwidth="0" marginheight="0" align="middle" scrolling="no" frameborder="0"></iframe>
加一個ID屬性
PS:如果網(wǎng)頁中加入以下頭
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
必須用 document.documentElement.scrollHeight關(guān)于這方面的東西
如果沒有文檔聲明可以用
document.body.scrollHeight
JavaScript技術(shù):JS獲取scrollHeight問題想到的標(biāo)準(zhǔn)問題,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。