Resize iframe to show first element works except in IE 7
I have two iframes on my home page, the script below is in the head of the page that is being displayed in the iframe, there are several divisions on the page in a container div with an id of 'content', I want to size the iframe on the home page so that just the first div is initially seen and to scroll to see the rest.
It is working in all browsers that I have tried except IE 7, I don't care too much about earlier browsers. IE 7 is acting like the page being shown is blank and sizing the iframe to 0 height, can someone tell me why IE 7 is having a problem with it, and failing that how can I get IE 7 to ignore the script?
function resizeIframe() {
//get the firstChild of a container 开发者_JAVA技巧div with the id 'content'
var div01 = document.getElementById("content").firstChild;
//find the first element ignoring white spaces and returns
while(div01.nodeType!=1){ div01 = div01.nextSibling; }
// get the height of first element
var boxHeight = div01.clientHeight;
//set the height of iframe the id of the iframe is 'news'
parent.document.getElementById('news').height = boxHeight; }
I have the function called in the body tag.
If someone could help me I'd very much appreciate it.
The page that it is on is at wsuu.org The version with the script is not up but you can get an idea of what I'm trying to do.
Rob
The problem was that IE 7 doesn't understand the clientHeight method it was returning 0 instead of the height of the element. I replaced it with offsetHeight which all browsers understand. I put the code on the home page and called the function in the body tag.
Here it the code.
function calcHeight2()
{
var div01=
document.getElementById('iframe2').contentWindow.
document.getElementById("content").firstChild;
while(div01.nodeType!=1){
div01 = div01.nextSibling;
}
var boxHeight = div01.offsetHeight;
document.getElementById('iframe2').height = boxHeight-5;
}
You can see it working at,
wsuu.org
精彩评论