10-11-2017 05:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-11-2017 05:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
How do I detect the screen width and height in javascript code?
Answered! Go to the Best Answer.

Accepted Solutions
10-11-2017 09:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-11-2017 09:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
10-11-2017 09:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-11-2017 09:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
06-01-2019 07:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-01-2019 07:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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}`);

