2012년 6월 11일 월요일

자바스크립트 나라별 국가별 체크

    function check(){
        var n = navigator,
            mobilePhones = new Array('iphone','ipod','android','blackberry','windows ce', 'nokia','webos','opera mini','sonyericsson','opera mobi','iemobile','safri'),
            uAgent = n.userAgent.toLowerCase(),
            type = n.appName,
            lang = (type=="Netscape") ? navigator.language : lang = navigator.userLanguage,
            href = "";

            lang = lang.substr(0,2); // 국가코드에서 앞 2글자만 자름

            function nation(lang){
                return {
                    "ko" : "korean.html",
                    "cn" : "china.html",
                    "else" : "else.html"
                }[lang];
            }
            href = nation(lang) || nation("else");

            for(var i=0;i<mobilePhones.length;i++){
                if(uAgent.indexOf(mobilePhones[i]) != -1) {
                    href = "m."+href;
                }
            }
            return document.location = href;
    }

댓글 1개:

  1. Ѕomebody essentially lend a hand to make significantly articles I might
    state. This іs the verу first time I frequented your wweb page and to this
    pоint? I surprised with the reѕearch you mаdee tо make this parrticular
    submit extraordinary. Great activity!

    my site :: http://androidappsgameshacks.com/iron-man-3-hack-tool

    답글삭제