3 回答

TA贡献2080条经验 获得超4个赞
iPad检测
通过查看userAgent属性,您应该能够检测到iPad用户:
var is_iPad = navigator.userAgent.match(/iPad/i) != null;
iPhone / iPod检测
同样,platform用于检查iPhone或iPods等设备的属性:
function is_iPhone_or_iPod(){
return navigator.platform.match(/i(Phone|Pod))/i)
}
笔记
当它起作用时,通常应该避免执行特定于浏览器的检测,因为它通常不可靠(并且可能被欺骗)。在大多数情况下,最好使用实际的特征检测,这可以通过Modernizr之类的库来完成。
正如Brennen的回答所指出的那样,在Facebook应用程序中执行此检测时可能会出现问题。请参阅他的答案以处理这种情况。

TA贡献1829条经验 获得超7个赞
我用这个:
function fnIsAppleMobile()
{
if (navigator && navigator.userAgent && navigator.userAgent != null)
{
var strUserAgent = navigator.userAgent.toLowerCase();
var arrMatches = strUserAgent.match(/(iphone|ipod|ipad)/);
if (arrMatches != null)
return true;
} // End if (navigator && navigator.userAgent)
return false;
} // End Function fnIsAppleMobile
var bIsAppleMobile = fnIsAppleMobile(); // TODO: Write complaint to CrApple asking them why they don't update SquirrelFish with bugfixes, then remove
添加回答
举报