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