简体   繁体   English

JavaScript检测iOS7的iPad

[英]javascript detect ios7 ipad

following the code from this question , I'm trying to add a class to html for handling iPad landscape layout issues. 按照这个问题的代码,我试图向html添加一个类来处理iPad横向布局问题。

But the JS to detect iPad iOS7 doesn't seem to work anymore: 但是用于检测iPad iOS7的JS似乎不再起作用:

if (navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i)) {
$('html').addClass('ipad ios7');
}

I tried it on an iPad4 iOS7. 我在iPad4 iOS7上尝试过。

Can anyone confirm that the detection code is working for them? 谁能确认检测代码对他们有用吗?

EDIT: thanks to Waki's test page, we can be sure it is working. 编辑:感谢Waki的测试页,我们可以肯定它正在运行。

And going through my 800 lines of app code again thoroughly, I found that I called my function that includes the code for the check from within document.ready but the function itself was placed outside of document.ready and therefore was not called. 然后再次遍历我的800行应用程序代码,我发现我调用了包含来自document.ready内部检查代码的函数,但该函数本身位于document.ready外部,因此未调用。 Really stupid mistake. 真是愚蠢的错误。 I apologize to all who wasted their time on reading this. 我向所有浪费时间阅读本文的人致歉。

are included jQuery library for use $('html') ? 是否包含使用$('html')的jQuery库? Because this regex is working. 因为此正则表达式正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM