简体   繁体   English

如果是手机,则在meta name =“ viewport”中添加“ width = device-width”

[英]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.

相关问题 iPhone视口元标记width = device-width不起作用 - iPhone viewport meta tag width=device-width not working 使用meta标签将ipad方向检测为width = device-width - detecting ipad orientation with meta tag as width=device-width 如何通过视口width = device-width来获取用于加载清晰图像但正确设置字体/ div大小的设备分辨率? - How get device resolution for loading sharp images but size fonts/divs properly with viewport width=device-width? 如何在Phonegap / JQuery mobile中以编程方式查找设备宽度 - How to programmatically find the device-width in Phonegap/JQuery mobile 查找设备宽度和回显元视口规则 - Finding device width and echoing meta viewport rule 键“宽度”的视口参数值“device-width;”无效,并且已被忽略。注意 - Viewport argument value “device-width;” for key “width” is invalid, and has been ignored. Note that 无法识别关键点“ width”的视区参数值“ device-width;”。 内容被忽略 - Viewport argument value “device-width;” for key “width” not recognized. Content ignored “ width = device-width”在移动浏览器上的固定大小的布局上并不总是有效吗? - “width=device-width” doesn't always work on fixed sized layout on mobile safari? 在设备宽度上更改视口宽度 - Change viewport width on device width 在CSS中使用设备宽度? JS的可能性? - Use device-width in CSS? JS possibilities?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM