복붙노트

[JQUERY] JavaScript / JQuery를 통해 Android 휴대 전화를 탐지합니다

JQUERY

JavaScript / JQuery를 통해 Android 휴대 전화를 탐지합니다

해결법


  1. 1.그걸보세요. http://davidwalsh.name/detect-Android

    그걸보세요. http://davidwalsh.name/detect-Android

    자바 스크립트 :

    var ua = navigator.userAgent.toLowerCase();
    var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
    if(isAndroid) {
      // Do something!
      // Redirect to Android-site?
      window.location = 'http://android.davidwalsh.name';
    }
    

    PHP :

    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
      header('Location: http://android.davidwalsh.name');
      exit();
    }
    

    편집 : 일부 의견에서 지적한 것처럼, 이것은 사건의 99 %에서 작동하지만 일부 가장자리 사례는 덮여 있지 않습니다. JS에서 훨씬 더 고급 및 방탄 된 솔루션이 필요한 경우 platform.js : https://github.com/bestiejs/platform.js를 사용해야합니다.


  2. 2.이 한 라이너는 어떻습니까?

    이 한 라이너는 어떻습니까?

    var isAndroid = /(android)/i.test(navigator.userAgent);
    

    i 수정자는 대소 문자를 구분하지 않는 일치를 수행하는 데 사용됩니다.

    Cordova AdMob 테스트 프로젝트에서 찍은 기술 : https://github.com/floatinghotpot/cordova-admob-pro/wiki/00.-how-to-use-with-phonegap-build.


  3. 3.나는 Michal의 대답이 최선이라고 생각하지만, 우리는 그것을 더욱 섭취하고 원래의 질문에 따라 Android CSS를 동적으로로드 할 수 있습니다.

    나는 Michal의 대답이 최선이라고 생각하지만, 우리는 그것을 더욱 섭취하고 원래의 질문에 따라 Android CSS를 동적으로로드 할 수 있습니다.

    var isAndroid = /(android)/i.test(navigator.userAgent);
    if (isAndroid) {
        var css = document.createElement("link");
        css.setAttribute("rel", "stylesheet");
        css.setAttribute("type", "text/css");
        css.setAttribute("href", "/css/android.css");
        document.body.appendChild(css);
    }
    

  4. 4.

    ;(function() {
        var redirect = false
        if (navigator.userAgent.match(/iPhone/i)) {
            redirect = true
        }
        if (navigator.userAgent.match(/iPod/i)) {
            redirect = true
        }
        var isAndroid = /(android)/i.test(navigator.userAgent)
        var isMobile = /(mobile)/i.test(navigator.userAgent)
        if (isAndroid && isMobile) {
            redirect = true
        }
        if (redirect) {
            window.location.replace('jQueryMobileSite')
        }
    })()
    

  5. 5.JS 버전, iPad도 잡기 :

    JS 버전, iPad도 잡기 :

    var is_mobile = /mobile|android/i.test (navigator.userAgent);
    
  6. from https://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery by cc-by-sa and MIT license