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.}
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

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

Back To Top