Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get screen width/height in code?i

ANSWERED

How do I detect the screen width and height in javascript code?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You need to get the root svg element by ID, then get the height/width from that element.

Ex:

let root = document.getElementById('root')
const screenHeight = root.height
const screenWidth = root.width

View best answer in original post

Best Answer
2 REPLIES 2

You need to get the root svg element by ID, then get the height/width from that element.

Ex:

let root = document.getElementById('root')
const screenHeight = root.height
const screenWidth = root.width
Best Answer

From https://dev.fitbit.com/build/guides/multiple-devices/#code-detection :

 

import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };
console.log(`Dimensions: ${device.screen.width} x ${device.screen.height}`);

 

Best Answer
0 Votes