53
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

[ jQuery ] ユーザーエージェント判定

jQueryでユーザーエージェント判定を行うコード

ua.js
$(function () {
    var ua = navigator.userAgent;
    if (ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) {
        // スマートフォン用コード
    } else if (ua.indexOf('iPad') > 0 || ua.indexOf('Android') > 0) {
        // タブレット用コード
    } else {
        // PC用コード
    }
})

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
53
Help us understand the problem. What are the problem?