The order in which things were happening was all wrong, and some key data was missing. That's what I get for not testing this, but I was busy with some real work. Using your demo, I came up with (too many changes to highlight):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
var excludes=[['test1.htm', 200], ['test_whatever.htm', 400]];
var testloaded = function(id){
var fobjs=window.frames, fels=document.getElementsByTagName('iframe');
for (var i = fels.length-1; i > -1; --i)
if(fels[i].id==id)
break;
var h = fobjs[i].location.href.replace(/^.*\/([^\/]*)/, '$1');
for (var j = excludes.length-1; j > -1; --j)
if(excludes[j][0]==h){
fels[i].height=excludes[j][1];
return false;
}
return true;
}
var iframeids=["mainframe"]
var iframehide="yes"
function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}
function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
if(frameid&&!testloaded(frameid))
return;
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
}
function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}
function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
</script>
</head>
<body>
<iframe id="mainframe" src="test1.htm" scrolling="auto" width="550" height="200"></iframe>
</body>
</html>
The major change that needs to be taken into account from your point of view is that the excludes array is now multidimensional, with each entry itself also being an array. The second part of each of these is the default height for the iframe for that excluded page.
Bookmarks