[英]How to read the property values of the viewport meta tag?
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
?我期待这些属性隐藏在
window
下的某个地方?
这将得到你所需要的......
document.querySelector('meta[name="viewport"]').getAttribute("content").split(',')[0].split('=')[1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.