3

While searching for a method to find out the window height, i came to know that 'document.body.clientHeight' is useful. I tried it in different situations everything failed. Failed means that it returns same value in all window heights.

Finally I removed the DOCTYPE declaration

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

and everything went ok. Now it return exact result.

Even html5 DOCTYPE

<!DOCTYPE html>

return invalid result.

I checked it in different browsers (Chrome, Opera, Firefox and IE).

What is the reason for that? Is there any other restrictions while using document.body? Is there any other things(variables, tags, methods, usage, etc) under the same scenario?

Thank you.

Vijeesh
  • 181
  • 10
  • possible duplicate of [JavaScript - Get Browser Height](http://stackoverflow.com/questions/3333329/javascript-get-browser-height) – Amit Feb 05 '14 at 11:31
  • Sorry for a 'misinterpretable' question. My interest is in knowing why that document.body.clientHeight return invalid result if it is under a standard? is it a bug? – Vijeesh Feb 05 '14 at 12:21

2 Answers2

2

Try this

document.getElementById("viewheight").innerHTML = window.innerHeight


   <!DOCTYPE html>,  puts the document into standards mode.

adding + "px" to the end of the size setting line
  document.getElementById("viewheight").innerHTML = document.body.clientHeight + "px";
user2804021
  • 151
  • 5
  • 2
    read this:- http://www.craiglotter.co.za/2009/01/23/javascript-why-doctype-affects-document-body-clientheight/ – user2804021 Feb 05 '14 at 11:39
1

use this to check window height

document.documentElement.clientHeight
Vytalyi
  • 1,637
  • 3
  • 20
  • 33