Get window width and height

Get window width and height
Get the window width and height in JavaScript using a cross-browser function that works with all versions of Internet Explorer and Firefox.
1. function GetWidth()
2. {
3.        var x = 0;
4.        if (self.innerHeight)
5.        {
6.                x = self.innerWidth;
7.        }
8.        else if (document.documentElement && document.documentElement.clientHeight)
9.        {
10.                x = document.documentElement.clientWidth;
11.        }
12.        else if (document.body)
13.        {
14.                x = document.body.clientWidth;
15.        }
16.        return x;
17.}
18. 
19.function GetHeight()
20.{
21.        var y = 0;
22.        if (self.innerHeight)
23.        {
24.                y = self.innerHeight;
25.        }
26.        else if (document.documentElement && document.documentElement.clientHeight)
27.        {
28.                y = document.documentElement.clientHeight;
29.        }
30.        else if (document.body)
31.        {
32.                y = document.body.clientHeight;
33.        }
34.        return y;
35.}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top