Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Essential JavaScript: 8 Cross-Browser Solutions-4 : Page 4

There's a core set of problems that every JavaScript developer will run across sooner or later. This article shows you how to deal with eight of the most common situations.


advertisement

Determining Display Characteristics
Problem 3: How can I find out my users' screen resolution? How can I determine the width and height of the browser window?

Two simple calls reveal the user's screen resolution in all three browsers:

   var screenH = screen.height;
   var screenW = screen.width;

However, the space you can use within a browser isn't the same as the screen resolution, even when the browser window is maximized—and users may be running the browser in an unmaximized window. Determining the browser's available width isn't as straightforward. IE4+ uses a proprietary property while both Netscape versions favor the W3C's standard properties:



   if(document.all){
      availW = document.body.clientWidth;
      availH = document.body.clientHeight;
   }else{
      availW = innerWidth;
      availH = innerHeight;
   }

To make matters worse, because IE uses properties of the document object (rather than the window object as in Netscape) you can't get the available space until after the document loads. You have to fire the code in the onLoad event (or later) to get meaningful results.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date