当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS获取scrollHeight问题想到的标准问题

Javascript
JS option location 页面跳转实现代码
ExtJS 简介 让你知道extjs是什么
ExtJs 学习笔记 Hello World!
ExtJs 学习笔记基础篇 Ext组件的使用
ExtJs 学习笔记 Ext.Panle Ext.TabPanel Ext.Viewport
漂亮的脚本日历,和大家分享
JS Tween 颜色渐变
js 图片轮播(5张图片)
开发跨浏览器javascript常见注意事项
通用JS事件写法实现代码
Js 订制自己的AlertBox(信息提示框)
js 浮动层菜单收藏
JavaScript入门教程(10) 认识其他对象
JQuery 常用方法基础教程
jQuery 页面载入进度条实现代码
jQuery Ajax 全解析
CSS+Table图文混排中实现文本自适应图片宽度(超简单+跨所有浏览器)
Ext JS Grid在IE6 下宽度的问题解决方法
js window.event对象详尽解析
JavaScript 悬浮窗口实现代码

Javascript 中的 JS获取scrollHeight问题想到的标准问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 253 ::
收藏到网摘: n/a

我在作一个iframe自动调整高度时,被嵌入的页面commit.asp的代码如下:
<!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>的相关评论</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();">
.
.
.
'
Asp代码
'
'
'
'
</body>
</html>
<script language=javascript>
<!--框架页自动调整尺寸-->
function zoomiframe()
{
parent.document.all("comment_load").style.height=document.body.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不能按照内容自动调高度。
后来我在zoomiframe()加入了一句alert(document.body.scrollHeight);。弹出来的值为0,但如果直接运行COMMIT。ASP弹出的高度却与内容相符。
实在搞不明白那里有冲途。我以前这样作可以,不知道论坛上有没有那个遇过这种问题。
谢谢!
复制代码 代码如下:

parent.document.all("comment_load").style.height=document.body.scrollHeight||document.documentElement.scrollHeight;

试了一下,应该是没什么问题的
<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:如果网页中加入以下头
复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

必须用 document.documentElement关于这方面的东西,最好搜下