JS获取scrollHeight问题想到的标准问题
JS获取scrollHeight问题想到的标准问题
发布时间:2016-12-30 来源:查字典编辑
摘要:我在作一个iframe自动调整高度时,被嵌入的页面commit.asp的代码如下:复制代码代码如下:的相关评论functionzoomifr...

我在作一个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">

<>

</style>

</head>

<body bgColor="transparent" onload="zoomiframe();">

</body>

</html>

<script language=javascript>

<>

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不能按照内容自动调高度。

后来我在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">

<>

</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.scrollHeight关于这方面的东西

如果没有文档声明可以用

document.body.scrollHeight

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类