I have tried:
var viewportElement = document.querySelector('meta[name="viewport"]'),
viewPort = {};
if (viewportElement) {
viewportElement.content.split(',').forEach(function (property) {
property = property.split('=');
viewPort[property[0]] = property[1];
});
}
console.log(viewPort);
It does give the expected result:
Object {width: "320", user-scalable: "no"}
However, I am not sure if reading values of these properties from the tag attribute value is the correct approach. I am expecting that these properties are hiding somewhere under the window
?
这将得到你所需要的......
document.querySelector('meta[name="viewport"]').getAttribute("content").split(',')[0].split('=')[1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.