Get Browser Viewport size with JavaScript

  • Avinash
  • 0
  • Jan 13, 2013
  • Web Development

This is quick article related to JavaScript we will see how we can get browser viewport size using Core JavaScript, MooTools and jQuery.

Core JavaScript

// Get Browser Viewport Width var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; // Get Browser Viewport Height var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// Get Browser Viewport Width
var width = window.innerWidth ||
            document.documentElement.clientWidth ||
            document.body.clientWidth;

// Get Browser Viewport Height
var height = window.innerHeight ||
             document.documentElement.clientHeight ||
             document.body.clientHeight;

jQuery

// Get Browser Viewport Width var width = $(window).width(); // Get Browser Viewport Height var height = $(window).height();
// Get Browser Viewport Width
var width = $(window).width();

// Get Browser Viewport Height
var height = $(window).height();

MooTools

// Get Browser Viewport Width var width = window.getSize().x; // Get Browser Viewport Height var height = window.getSize().y;
// Get Browser Viewport Width
var width = window.getSize().x;

// Get Browser Viewport Height
var height = window.getSize().y;

Hope you find this quick tip helpful, Also consider sharing the same thing for other JavaScript frameworks.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: