JavaScript to display window size

PapaGeek

New Member
I wrote the following JavaScript to display the screen resolution and the size of the browser window:

height = screen.height;
width = screen.width;
document.write( width + " x " + height + "<br>");
if (document.layers) {
width = window.innerWidth;
depth = window.innerDepth;
}
// Explorer 6 Strict Mode
else if (document.documentElement && document.documentElement.clientHeight) {
width = document.documentElement.clientWidth;
depth = document.documentElement.clientHeight;
}
else if (document.all) {
width = document.body.clientWidth;
depth = document.body.clientHeight;
}
document.write( width + " x " + depth);

The size of the window always displays as 0 x 0 when the page is displayed, then displays the correct values when the page is refreshed.

What is the proper way to write this script?
 

jasikajohnson

New Member
Here the Java script is a perfect you use this it work proper way you write in a <script></script >tag this a way you write here a code you put in this tag and it work.
 

Jabulani

New Member
Gracias Mi Amigo!,

I have a project that ask for an answer almost similar to your code. The most important part of that project is to show the process on how we came up with the particular solution. It is the classic "show me the process not just the final answer" thing. I can also sense that you have been coding in your entire life. Your code is neat and wasted no lines and extra spacing at all.
 
Top