0

I was just playing around in the console, and noticed that if I type:

body it returns <body>...</body>

This is obviously the same as window.body, which therefore also returned <body>...</body>

Then document.body also returns <body>...</body> as expected, as the body is part of the document object, and as far as I was aware, not the window object.

For this reason I expected window.body to return undefined.

Then I checked window.head which returned undefined.

This is the result I expected to happen with window.body

Finally, document.head returned <head>...</head> as expected.

Can anyone explain where window.body comes from? A search on google, and stackoverflow couldn't answer this one for me.

Paul Fitzgerald
  • 11,770
  • 4
  • 42
  • 54

1 Answers1

0

The window.body element is not the same as the document.body element unless some javascript on the page has already assigned that as a helper method.

As mentioned in the comments on your question, the default would be undefined for window.body (and hence simply body).

Here are 3 screenshots from Chrome, Safari and Firefox consoles showing what the google homepage (google.co.uk in this case) sets as the result of window.body compared with document.body. Clearly not the same as document.body, therefore you can tell they've done that themselves for a particular reason (as had the page you're looking at possibly):

Chrome

enter image description here

Safari

enter image description here

Firefox

enter image description here

Hope that helps.

Community
  • 1
  • 1
toomanyredirects
  • 1,972
  • 15
  • 23