首頁  >  文章  >  web前端  >  JavaScript–Apple裝置偵測範例程式碼_javascript技巧

JavaScript–Apple裝置偵測範例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:15:041164瀏覽

這裡提供一些javascript偵測程式碼,用來偵測iPhone、iPod、iPad設備。

複製程式碼 代碼如下:

/// Apple detection object


/// 🎜> };
Apple.UA = navigator.userAgent;Apple.Device = false;

Apple.Types = ["iPhone", "iPod", "iPad"];

for (var d = 0; d   var t = Apple.Types[d];
  Apple[t] = !!Apple.UA.match( new RegExp(t, “i”));

  Apple.Device = Apple.Device || Apple[t];

}

// is this an Apple device?
alert(
  “Apple device? ” Apple.Device
  “ iPhone? ” Apple.iPhone
  “ iPod? ” Apple.iPod
  “ iPad? ” Apple.iPad

);
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn