JS獲取scrollHeight問題想到的標準問題
更新時間:2007年05月27日 00:00:00 作者:
如果沒有文檔聲明可以用 document.body.scrollHeight,如果有文檔聲明必須用 document.documentElement.scrollHeight關(guān)于這方面的東西
我在作一個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,但如果直接運行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
您可能感興趣的文章:
- js中top、clientTop、scrollTop、offsetTop的區(qū)別 文字詳細說明版
- js中scrollHeight,scrollWidth,scrollLeft,scrolltop等差別介紹
- js獲取height和width的方法說明
- js中top/parent/frame概述及案例應(yīng)用
- 利用JS解決ie6不支持max-width,max-height問題的方法
- js中的preventDefault與stopPropagation詳解
- js中top的作用深入剖析
- window.top[_CACHE]實現(xiàn)多個jsp頁面共享一個js對象
- JS獲取iframe中marginHeight和marginWidth屬性的方法
- JS中完美兼容各大瀏覽器的scrolltop方法
- js中不同的height, top的區(qū)別對比
相關(guān)文章
form表單中去掉默認的enter鍵提交并綁定js方法實現(xiàn)代碼
form表單中默認的enter提交是不是讓你已經(jīng)很耐煩了吧,本文主要講解一下如何去掉默認的enter鍵提交同時綁定js方法,感興趣的朋友可以參考下哈2013-04-04
JavaScript執(zhí)行環(huán)境及作用域鏈實例分析
這篇文章主要介紹了JavaScript執(zhí)行環(huán)境及作用域鏈,結(jié)合實例形式分析了JavaScript執(zhí)行環(huán)境及作用域鏈的相關(guān)概念、功能與使用技巧,需要的朋友可以參考下2018-08-08
javaScript實現(xiàn)鼠標在文字上懸浮時彈出懸浮層效果
這篇文章主要為大家詳細介紹了javaScript實現(xiàn)鼠標在文字上懸浮時彈出懸浮層效果的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-03-03

