Script crashing on document usage (iFrames)

L

Lone Wolf

Has anyone exprienced and solved a problem where the javascript script
will crash when trying to access the document property of a page loaded
within an iFrame? This problem does not appear to always happen,
however on pages where the problem occurs once, it will always occur.

Below is an example script of the problem (Note: This problem appears
in both IE 6, and FireFox)
-------------------------------------------------------------------------------

function setHeight() {
var iframeWin = window.frames["iframeName"];
var iframeEl = document.getElementById?
document.getElementById(iframeName): document.all?
document.all[iframeName]: null;
if ( iframeEl && iframeWin ) {
iframeEl.style.height = "1200"; // helps resize (for some) if new
doc shorter than previous
var docHt = getDocHeight(iframeWin.document);
}
}

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;
}

<iframe src="src" name="iframename" id="iframename"
onLoad="setHeight()"></iframe>

-----------------------------------------------------------------------

Note: When posting out the object representation for the document the
logic will crash with no error given, when trying to access any
property of the document the log will crash with no error being given.

Lone Wolf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
Best cryptoconsultant

Latest Threads

Top