最佳方法来检测iPad Safari用户 [英] Best approach to detect iPad Safari user

查看:196
本文介绍了最佳方法来检测iPad Safari用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为检测iPad Safari用户添加代码的最佳方法是什么?我的意思是我们应该使用
1. CSS(通过链接媒体..)
2. JS(通过导航器对象)

What is the best approach to add code for detecting an iPad Safari user. I mean should we use 1. CSS (through link media..) 2. JS (through navigator object)

使用用户代理字符串不是检测iPad的最佳方法,因为不一致。

I have heard that using user-agent string is not the best way to detect iPad, because of inconsistencies.

请建议。非常感谢。

我也有后续问题:

实际上,检测桌面/ iPad的代码将成为JSP的一部分(而不是静态HTML文件)...现在在我的应用程序,有超过200页。然后我应该在哪里添加代码检测和我应该如何添加它?我的意思是我必须更新在servlet web.xml文件中的某个地方。

Actually the code to detect desktop/iPad is going to be part of JSP (and not static HTML files)...Now in my app, there are 200+ pages..So where exactly should I be adding the code for detection and how exactly should I add it? I mean do I have to update somewhere in the servlet web.xml file..

对于混合的2个问题,但只是添加在这里,因为两个都是相关的问题。 。

Sorry for mixing the 2 questions..But just added here as both are related questions..

推荐答案

您在用户代理中始终有iPad。

You always have iPad in the user-agent.

请参阅如果您要定位iPad,以便您可以显示不同的内容, https://github.com/madrobby/zepto/blob/master/src/detect.jsrel =nofollowtitle =detect.js>这里 ZeptoJS如何在JS中检测iPad。

See here how ZeptoJS detects iPad in JS.

要以两个方向定位iPad,请执行以下操作:

To target iPad in both orientations, do this:

<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="ipad-portrait.css"> 
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="ipad-landscape.css">

这篇关于最佳方法来检测iPad Safari用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆