The standard problem of JS acquiring scrollheight problem _javascript skill

Source: Internet
Author: User
Tags commit

I'm making an iframe. When the height is automatically adjusted, the code for the embedded page commit.asp is as follows:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Related Comments </title>
<style type= "Text/css" >
<!--
Body {
margin-left:0px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
}
-->
</style>
<body bgcolor= "Transparent" onload= "zoomiframe ();" >
</body>
<script language=javascript>
<!--frame page automatic sizing-->
function Zoomiframe ()
{
Parent.document.getElementById ("Comment_load"). Style.height=document.documentelement.scrollheight;
}
</script>

Then insert other code on the other page and embed the page in another page
<iframe src= "comment.asp?classid=2&id=12" allowtransparency= "true" Name= "Comment_load" "width=" 540 "height=" "marginwidth=" 0 "marginheight=" 0 "align=" Middle "scrolling=" no "frameborder=" 0 "></iframe>

But no effect, the IFRAME can not automatically adjust the height of the content.
Later I added an alert (document.body.scrollHeight) to Zoomiframe (). The value of bouncing out is 0, but if you run commit directly. The height of the ASP popup is consistent with the content.
I really don't understand where there is a rush. I used to do this, I do not know whether the forum has encountered such a problem.
Thank you!
Copy Code code as follows:

Parent.document.all ("Comment_load"). Style.height=document.body.scrollheight| | Document.documentElement.scrollHeight;

Try it, there should be no problem.
<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=" "marginwidth=" 0 "marginheight=" 0 "align=" Middle "scrolling=" no "frameborder=" 0 "></iframe>

Add an id attribute

PS: If you add the following headers to your Web page
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

You have to use Document.documentElement.scrollHeight to do something about it.
If there is no document declaration to use
Document.body.scrollHeight

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.