Is it possible to detect whether the browser will scale the website based on the meta viewport element?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
There isn't any JavaScript method to detect if the meta viewport will be applied. However, you can check if it was applied via two step process with inline js in the head, with an approach such as:
This works with responsive design in most common case on mobile because the initial/default viewport of mobile devices is 980px (http://www.quirksmode.org/mobile/metaviewport/) which isn't a common desktop screen-with at all. And no current desktop browsers support the meta-viewport.
I am going to use this method as factor to detect a mobile device in that respect. However, its worth noting that there are exceptions. So you can't rely on the above method alone for all devices.
e.g. With the Blackberry Playbook, the default viewport sizes already match the 600x1024 pixel size of
device-width, initial-scale=1
, so clientWidth will not change despite meta-viewport rescaling.No, the meta viewport element just tells the mobile browser how it should handle the current page. So, it depends a bit what you will do.
If you will catch resize events then you can do it with some javascript:
Or if you just want to add different styles on different screen sizes then use media queries in your css file like: