I'm trying to use an Iframe auto-height, and the code that served me most was this:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>THE IFRAME HOLDER</title>
<script>
function alertsize(pixels){
pixels+=32;
document.getElementById('myiframe').style.height = pixels+"px";
}
</script>
</head>
<body style="background:silver;">
<iframe src='theiframe.htm' style='width:458px;background:white;' frameborder='0' id="myiframe" scrolling="auto"></iframe>
</body>
</html>
Iframe: Save with the name "theiframe.htm"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>IFRAME CONTENT</title>
<script>
function toggle(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'block' ) el.style.display = 'block';
else el.style.display = 'none';
parent.alertsize(document.body.scrollHeight);
}
</script>
</head>
<body onload="parent.alertsize(document.body.scrollHeight); " >
<a href="javascript:toggle('moreheight')">toggle height?</a><br />
<div style="display:none;" id="moreheight">
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
more height!<br />
</div>
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
THE END
<div style="clear:both;"></div>
</body>
</html>
In IE, Opera and Firefox, it works perfectly. In Chrome and Safari, does not seem to work. A friend said that the problem is possibly here:
onload="parent.alertsize(document.body.scrollHeight);"
Example in Chrome: http://www.warezexpress.com/ups/2009_setembro/chrome.jpg
Example in Safari: (the iframe expands, and does not decrease) http://www.warezexpress.com/ups/2009_setembro/safari.jpg
But I still do not understand JavaScript to solve this. I took this code ready in a forum. Thanks for any word!