How do I detect the screen width and height in javascript code?
Answered! Go to the Best Answer.
Best AnswerYou 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
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