0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryでUA判定して適宜スタイルシートを呼び出す

Posted at

解決案

likethis.html
<script>
  $(function () {
    var ua = navigator.userAgent;
    if (ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) {
      $('link').html('<link rel="stylesheet" href="styles/android.min.css" />');
    }
  })
</script>

補足

navigator.userAgent

  • Navigatorオブジェクトの「userAgentプロパティ」
  • JavaScriptを実行しているブラウザのUserAgent(種類やバージョンなど)の情報を取得できる

参考 http://www.htmq.com/js/navigator_userAgent.shtml

OS判断文字列

likethis.html
if (ua.indexOf('ここに入れるやつ') > 0
OS 文字列
Windows 「Windows」
Mac 「Mac + OS」
iOS 「Mac + OS + iPhone」「Mac + OS + iPad」「Mac + OS + iPod」
Android 「Android」
  • Windows Phoneは「Windows + Phone」
  • 「Android」には「Linux」も含まれている

参考 https://htaccess.cman.jp/useragent/os/

どういう状況で使うねん

  • AndroidとiOSでデザインが異なるアプリのLPの時に使うことができる
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?