javascript get window width code example

Example 1: how to get the height of window in javascript

//get screen height of the device by using
window.innerHeight
//get screen width of the device by using
window.innerWidth

Example 2: get window size javascript

const window {
  width: window.innerWidth,
  height: window.innerHeight
}

Example 3: JS get viewport width

//getting the viewport dimensions
var width= Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

Example 4: get screen width javascript

window.screen.width
//or just
screen.width

Example 5: js window dimensions

// better than using window.innerWidth / window.innerHeight 
// because of scrollbars
const client = {
      width: document.documentElement.clientWidth,
      height: document.documentElement.clientHeight
}

Example 6: java script find screen size of device

// Size of browser viewport.
$(window).height();
$(window).width();

// Size of HTML document (same as pageHeight/pageWidth in screenshot).
$(document).height();
$(document).width();

Tags:

Java Example