I'm trying to figure out if there's a way to detect the page zoom level that users set in their desktop browsers. For instance, if a user visits my website, sets the zoom to 75%, and then returns later, I'd like to automatically retrieve that zoom level (75%) so I can adjust my website's content accordingly. Is this feasible?
3 Answers
I understand your intention, but detecting zoom levels can be tricky. I personally tried storing `devicePixelRatio` in `localStorage` during the user's first visit and then calculating the zoom level based on that. However, it fails in Safari since it doesn't update `devicePixelRatio` when zooming. You might want to look for a workaround for those browsers.
You're heading for a lot of frustration with this feature! There are so many factors that change display settings based on the machine. It might be best to go for a responsive design instead.
Unfortunately, it's not possible to directly retrieve the page zoom level in desktop browsers. They typically maintain the user's preferred zoom level, but there's no built-in way to access that data through JavaScript.
Interesting method! I usually just focus on responsive design to avoid such issues. Have you noticed any improvement in how your charts display?