检测触摸屏(ipad,iphone等)的最佳方法是什么?

Eva*_*nss 6 css touchscreen

如果在ipad或iphone等触摸屏设备上查看,我需要为我的页面加载一些额外的CSS.这是最简单的方法吗?谢谢

dma*_*man 6

对于iPad,您可以尝试:

 if (window.Touch)
  {
    alert("touch my ipad/iphone/ipod");
  }
  else
  {
    alert("no touch!");
  }
Run Code Online (Sandbox Code Playgroud)

我冒昧地猜测iPhone的工作原理是一样的.

您还可以使用CSS媒体查询来生成以下内容:

<link rel="stylesheet" media="all and (max-device-width: 480px)" href="iphone.css"> 
<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"> 
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="ipad-landscape.css"> 
Run Code Online (Sandbox Code Playgroud)


Wya*_*ett 3

最简单的可以说是http://www.modernizr.com/