473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

checking 'document.body' availability (opera)

Hi, I'm wanting to check the availability of the 'document.body'
element.

In Mozilla and IE, the function below:

window.onload = function(){
alert(document.body);
};

alerts '[object HTMLBodyElement]' or '[object]', so I could use the
'window.onload' event as the sign of 'document.body' element available.

but in Opera(8.01), it alerts 'null', and it tells the 'document.body'
element is not loaded yet.
after which 'window.' event, 'document.body' is become
available(ensured) for Opera?

thanks in advance

Aug 24 '05 #1
7 2315


Sundew Shin wrote:

In Mozilla and IE, the function below:

window.onload = function(){
alert(document.body);
};

alerts '[object HTMLBodyElement]' or '[object]', so I could use the
'window.onload' event as the sign of 'document.body' element available.

but in Opera(8.01), it alerts 'null'


That sounds rather odd, could you post a URL where that happens?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 24 '05 #2
http://wednus.com/test.htm

code:

<html>
<head>
<script>
window.onload = function(){
alert(document.body);
};
</script>
</head>
</html>
thanks.

Aug 24 '05 #3
a ha!

I have realized that there is no '<body></body>' tag in my test code.

so the fact is, Mozilla & IE generates 'document.body' element
automatically even when the scriptor forget to write it, but opera
doesn't.

I still don't understand why it implemented differently though..

Aug 24 '05 #4


Sundew Shin wrote:
http://wednus.com/test.htm

code:

<html>
<head>
<script>
window.onload = function(){
alert(document.body);
};
</script>
</head>
</html>


That is an edge case, you realize that your HTML document does not
contain a <body> element. While other browsers automatically add a body
element to the DOM (and the HTML 4 SGML DTD supports that) I think it is
known that Opera does not do that. I don't know whether Opera intends to
fix that, you could ask in a group on news.opera.com.
But I am pretty sure that document.body is an element object in Opera's
DOM if your HTML document really contains a <body> element.
Why exactly do you need to use a source document without a <body> element?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 24 '05 #5
thanks for your kind explanation, and I actually have no specific
reason to avoid <body>. it was just happend while I was making my
prog. to support opera. thanks.

Sundew Shin
Wednus Project
Developer/Manager
http://wednus.com

Aug 24 '05 #6
Martin Honnen <ma*******@yahoo.de> writes:
Sundew Shin wrote:
<html>
<head>
<script>

....
While other browsers automatically add a
body element to the DOM (and the HTML 4 SGML DTD supports that) I
think it is known that Opera does not do that.


Perfectly reasonable, since there is no indication that the page is
HTML 4 (and quite a lot that it isn't, like missing DOCTYPE declaration,
title element, type attribute on script element and ... missing body
element :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 24 '05 #7


Lasse Reichstein Nielsen wrote:
Perfectly reasonable, since there is no indication that the page is
HTML 4 (and quite a lot that it isn't, like missing DOCTYPE declaration,
title element, type attribute on script element and ... missing body
element :)


Opera has troubles creating a head element for instance in this valid
HTML 4 document:
<http://home.arcor.de/martin.honnen/operaBugs/op8/headMissingInDOM1.html>
So even when the HTML 4 DTDs suggest that the parser needs to add an
element like the <head> element Opera does not do that.

But you are right that the original test case needs improvements like a
body element or some body element content added to make it valid HTML
and then to be able to decide whether the DOM should have an element
object or not.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 24 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Konrad Mathieu | last post by:
Does this work in most browsers, namely MSIE? document.links.href or does it have to be document.links.href ?
2
by: Eric Pickup | last post by:
I'm having a problem with the following html (I've simplified it down to a simple test case). Could anyone point out why Mozilla is having problems with this (I've tried so many variations that I...
3
by: F | last post by:
It seems that document.cookie doesn't work both on Internet Explorer 5 for Mac (OS 9) and Opera 6 for PC... am I doing something wrong? Or does it just not work? I don't get an error message, the...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
3
by: Alexander Mikhailian | last post by:
I have an http = new XMLHttpRequest(); that provides me with an http.responseXML. Somewhere deep in the http.responseXML there is a fragment called e.g. mydom that I want to copy with all its...
1
by: alex.sherwin | last post by:
Working on a google homepage module. One of the things I do is retrieve results from a search into a string. I want to be able to access all the anchors in this string, (their name, href, and...
7
by: dd | last post by:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly I've been searching for the answer for two hours and I decided to finally post this question. I'm trying to take a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.