채택완료

갤럭시,아이폰 구분 스크립트좀 알려주세요

2019-05-11 (토) 18:01:30 3,835

아이폰,갤럭시 각 기기에서 링크 클릭시

각 앱스토어로 넘어가게 하려고 하는데

인터넷보고 해봤는데 안되네요 ㅠㅠ

뭐가 잘못된건가요??

<script>
    var is_mobile = "N";
    var ios_app_download_url = "아이폰주소";
    var android_app_download_url = "갤럭시주소";
    var pc_app_download_url = "pc주소";

    var iframe = document.createElement('iframe');
    var visited_at = (new Date()).getTime(); // 방문 시간

    if (is_mobile == 'Y') {
        var scheme = "petfriends://";
        var userAgent = navigator.userAgent;
        userAgent = userAgent.toLowerCase();

        if (userAgent.match(/android/)) {
            if (userAgent.match(/chrome/)) {
                scheme = "intent://main#Intent;scheme=petfriends;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=com.fineappstudio.android.petfriends;end";

                setTimeout(function() {
                    window.location.href = scheme;
                }, 1000);
            } else {
                window.location.href = pc_app_download_url;
            }
        } else {
            setTimeout(
                function() {
                    if ((new Date()).getTime() - visited_at < 2000) {
                        window.location.href = ios_app_download_url;
                    }

                }, 500);
            setTimeout(function() {
                window.location.href = scheme;
            }, 0);
        }
    } else {
        window.location.href = pc_app_download_url;
    }
</script>
 

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

요건 안되건가요?

요렇게한번 해보세유 테스트는 못해봤습니다!

클릭하기 전부터 기기정보를 수집해서

기기별로 각각 다른 링크를 보여주면 되지않을까 합니다!

Copy
var varUA = navigator.userAgent.toLowerCase(); //userAgent

if (varUA.match('android') != null) { 

    //안드로이드 일때 처리

} else if (varUA.indexOf("iphone")>-1||varUA.indexOf("ipad")>-1||varUA.indexOf("ipod")>-1) { 

    //IOS 일때 처리

} else {

    //아이폰, 안드로이드 외 처리

}

답변에 대한 댓글 1개

주소는 어디다가 넣어야 되나요?

답변을 작성하려면 로그인이 필요합니다.