10 examples of 'javascript get window width' in JavaScript

Every line of 'javascript get window width' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
94function _getWindowWidth() {
95 return window.innerWidth;
96}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

338function getBrowserWidth () {
339 if (document.documentElement && document.documentElement.clientWidth) {
340 return document.documentElement.clientWidth;
341 } else if (window.innerWidth) {
342 return window.innerWidth;
343 } else if (document.body && document.body.clientWidth) {
344 return document.body.clientWidth;
345 } else if (document.body && document.body.offsetWidth) {
346 return document.body.offsetWidth;
347 }
348 return 0;
349}
2function getBrowserWidth()
3{
4 if (window.innerWidth)
5 {
6 return window.innerWidth;
7 }
8 else if (document.documentElement && document.documentElement.clientWidth != 0)
9 {
10 return document.documentElement.clientWidth;
11 }
12 else if (document.body)
13 {
14 return document.body.clientWidth;
15 }
16 return 0;
17}
54get width(): number | Promise<number> {
55 return this.request(`${this.prefix}get_width`, [this]);
56}
93function findWindowWidth()
94{
95 return window.innerWidth || document.documentElement.clientWidth;
96}
84get innerWidth() { return this.width; }
59set width(width: number | Promise<number>) {
60 this.request(`${this.prefix}set_width`, [this, width]);
61}
129function get_width(obj) {
130 return typeof obj == 'object' && obj && obj.width != undefined
131 ? obj.width
132 : ((typeof obj == 'object' && obj !== null ? utils.strlen(obj.text) : utils.strlen(obj)) + (style['padding-left'] || 0) + (style['padding-right'] || 0))
133}
150function getViewportWidth() {
151 if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
152 return document.documentElement.clientWidth;
153 }
154 else if (document.compatMode && document.body) {
155 return document.body.clientWidth;
156 }
157 return self.innerWidth;
158};
34function getWidth(){
35 // see http://bugs.dojotoolkit.org/ticket/17962
36 var rowWidth = domStyle.get(dom.byId("trow"), "width");
37 doh.t(rowWidth > 0, "width: " + rowWidth);
38}

Related snippets