Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic document height set by loaded iframe

Status
Not open for further replies.

kharddie

Instructor
Feb 7, 2006
23
AU
i downloaded this code that resizs the document height to the loaded iframe....is there any way that the var docHt (document height) can change every second because links in the iframe are specific to the set loaded iframe height.....please help

here is the code.....

function getDocHeight(doc) {
var docHt = 0, sh, oh;
if (doc.height) docHt = doc.height;
else if (doc.body) {
if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
if (sh && oh) docHt = Math.max(sh, oh);
}
return docHt;
}

function setIframeHeight(iframeName) {
var iframeWin = window.frames[iframeName];
var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
if ( iframeEl && iframeWin ) {
iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
var docHt = getDocHeight(iframeWin.document);
// need to add to height to be sure it will all show
if (docHt) iframeEl.style.height = docHt + 30 + "px";
}
}

function loadIframe(iframeName, url) {
if ( window.frames[iframeName] ) {
window.frames[iframeName].location = url;
return false;
}
else return true;
}
</script>




<body onLoad="setIframeHeight('ifrm')" leftmargin="0" topmargin="0">
 
If you want to do something on an interval, you can use the setInterval command to do this. For example, the following would run the function named 'yourFunc' every 1 second (1000 milliseconds). I'm sure that from this, you can adapt it to call your own function.

Code:
setInterval('yourFunc();', 1000);

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks BillyRayPreachersSon for ur reply .can u pls elaborate on that?????how do i put the setInterval command to target setIframeHeight('ifrm')in my script ...i would appreciate more help thanks BRPSon.
 
hey
i have replaced this <body onLoad="setIframeHeight('ifrm')" leftmargin="0" topmargin="0"> with this <body onLoad="setInterval('setIframeHeight('ifrm')', 1000); "> but nothing happens so dont know where the problem is??????

this didnt work either
<body onLoad="javascript:setInterval('setIframeHeight('ifrm')', 1000); ">
kharddie
 
Look at your single quotes - you have single quotes nested in side single quotes, so of course it wont work properly.

You need to escape the inner set using a backslash... so use \' instead of ' for the quotes surrounding the strig "ifrm".

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks so much BillyRayPreachersSon for that help ..it works perfect
kharddie
 
hey one more prob, my images keep flashing using setInterval(setIframeHeight() is there any way i stop the loop afre two sec

tried this but doesnt work -----
function newloadedheight() {
showtime=setInterval('setIframeHeight( \'ifrm\')', 1000);
if (showtime){
clearInterval(showtime);
}
}

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top