[英]Add “width=device-width” in meta name=“viewport” if mobile phone
need to add "width=device-width" in meta name="viewport" if mobile phone. 如果是手机,则需要在元名称=“ viewport”中添加“ width = device-width”。 trying to use this to no avail:
试图使用它无济于事:
//iPhone Fix
jQuery(document).ready(function(){
if (jQuery(window).width < 767) {
var meta = document.getElementsByTagName("meta");
meta.setAttribute("width","device-width");
}
});
If i dont set width="device-width" in the meta tag, site looks great on phones and media.css kicks in, but tablets become distorted. 如果我未在meta标记中设置width =“ device-width”,则该网站在手机和media.css上看起来不错,但平板电脑会变形。 Any help would be great.
任何帮助都会很棒。 Thanks
谢谢
I think you have just a little error in your code, this should work: 我认为您的代码中只有一点错误,这应该可以工作:
//iPhone Fix
jQuery(document).ready(function(){
if (jQuery(window).width < 767) {
var meta = document.getElementsByTagName("meta");
meta[0].setAttribute("width","device-width");
}
});
In your original code, you tried to use the setAttribute
method on an array of elements and not an element itself. 在原始代码中,您尝试在元素数组而非元素本身上使用
setAttribute
方法。 Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.