Forum Moderators: open

Message Too Old, No Replies

'contentDocument.body' is null or not an object

iframe auto height

         

guod

10:37 pm on Nov 26, 2010 (gmt 0)

10+ Year Member



Due to limitations with our ecommerce cart, we need to call a page using iframe. As you know getting an iframe to have auto height needs some extra code. I found a script that resized the iframe, but in IE the page loads with an error....I put up a page with an old product that is missing images, but the iframe is still there and still give the error. Here is a link to the page.
[yazmo.com ] Any ideas as to how I can fix this? Thanks




Here are the error details:


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Timestamp: Fri, 26 Nov 2010 22:35:58 UTC


Message: 'contentDocument.body' is null or not an object
Line: 19
Char: 1
Code: 0
URI: [yazmo.com...]

Fotiman

2:25 pm on Nov 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A couple of things. Your autoheight.js file has some problems. First, it contains some funky characters (in the comments) that you may want to remove. However, the main problem is this bit of code:

function setHeight(e){
if (e.Document && e.Document.body.scrollHeight) //ie5+ syntax
e.height = e.contentWindow.document.body.scrollHeight;
else if (e.contentDocument && e.contentDocument.body.scrollHeight) //ns6+ & opera syntax
e.height = e.contentDocument.body.scrollHeight + 35;
else (e.contentDocument && e.contentDocument.body.offsetHeight) //standards compliant syntax � ie8
e.height = e.contentDocument.body.offsetHeight + 35;
if(e.contentDocument){
e.height = e.contentDocument.body.offsetHeight + 80;
} else {
e.height = e.contentWindow.document.body.scrollHeight;
}
}

I'm going to clean it up some to make it easier to work with:

function setHeight(e) {
if (e.Document && e.Document.body.scrollHeight) //ie5+ syntax
e.height = e.contentWindow.document.body.scrollHeight;
else if (e.contentDocument && e.contentDocument.body.scrollHeight) //ns6+ & opera syntax
e.height = e.contentDocument.body.scrollHeight + 35;
else (e.contentDocument && e.contentDocument.body.offsetHeight) //standards compliant syntax � ie8
e.height = e.contentDocument.body.offsetHeight + 35;
if (e.contentDocument) {
e.height = e.contentDocument.body.offsetHeight + 80;
} else {
e.height = e.contentWindow.document.body.scrollHeight;
}
}

The 6th line contains:

else (e.contentDocument && e.contentDocument.body.offsetHeight)

However, and "else" case doesn't take a condition. I think that you meant this to be:

else if (e.contentDocument && e.contentDocument.body.offsetHeight)

So I would try that first. Also, I would suggest adding more curly braces:


function setHeight(e) {
if (e.Document && e.Document.body.scrollHeight) { //ie5+ syntax
e.height = e.contentWindow.document.body.scrollHeight;
} else if (e.contentDocument && e.contentDocument.body.scrollHeight) { //ns6+ & opera syntax
e.height = e.contentDocument.body.scrollHeight + 35;
} else if (e.contentDocument && e.contentDocument.body.offsetHeight) { //standards compliant syntax � ie8
e.height = e.contentDocument.body.offsetHeight + 35;
}
if (e.contentDocument) {
e.height = e.contentDocument.body.offsetHeight + 80;
} else {
e.height = e.contentWindow.document.body.scrollHeight;
}
}

guod

4:45 pm on Nov 29, 2010 (gmt 0)

10+ Year Member



thanks for the reply. I will try it the second I get to the office

guod

5:10 pm on Nov 30, 2010 (gmt 0)

10+ Year Member



I just did a nice copy and paste of your code and it WORKS! thanks a lot man.

Fotiman

6:35 pm on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad to help. :)