jquery 클라이언트의 유형 판단

10711 단어 jquery
//       

var isAndroid = navigator.userAgent.toLowerCase().match(/android/i) == "android";

var isIphone = navigator.userAgent.toLowerCase().match(/iphone os/i) == "iphone os";

var isIpad = navigator.userAgent.toLowerCase().match(/ipad/i) == "ipad";

var isWin = navigator.userAgent.toLowerCase().match(/windows phone/i) == "windows phone";

var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");

//      ,  url  get   

(function($) {

  $.extend({ 

    urlGet:function()

    {

      var aQuery = window.location.href.split("?"); //  Get  

      var aGET = new Array();

      if(aQuery.length > 1)

      {

        var aBuf = aQuery[1].split("&");

        for(var i=0, iLoop = aBuf.length; i<iLoop; i++)

        {

          var aTmp = aBuf[i].split("="); //  key Value

          aGET[aTmp[0]] = aTmp[1];

        }

      }

      return aGET;

    }

  })

})(jQuery);





$(document).ready(function(){

        var curr_url = window.location.href;

        var host = window.location.host;

        var GET = $.urlGet(); 

        var curr_url = GET['url_download'];

        if(isAndroid || isIpad || isIphone || isWin){

       //      

            $(".addthis_sharing_toolbox").show();

            //ajax  ,         

            if(curr_url.indexOf(".exe")!=-1||curr_url.indexOf(".dmg")!=-1){

                $.ajax({     

                    url:'http://'+host+'/index.php/Index/mobile_url',     

                    type:'post',     

                    data:{url:curr_url},     

                    async : true,  

                    error:function(){     

                        alert('error');     

                    },

                    success:function(data){

              //

                        $(".box1").show();

                        $(".box2").hide();

                        $(".addthis_sharing_toolbox").show();

                        $(".discountCode").show();

                        var json = eval('(' + data + ')');

                        $("#win_price").html(json.win_price);

                        $("#mac_price").html(json.mac_price);

                        $("#win_btn").attr('href',json.win_buy);

                        $("#mac_btn").attr('href',json.mac_buy);

                        $("#share_code").attr('data-url',json.skip_url);

                        $("#share_code").attr('data-title',json.skip_title);

                    }

                });

            }

        }else{

       //pc    ,        

            $(".box1").hide();

            $(".box2").show();

            $("#pc_download").attr('href',curr_url);

            location.href=curr_url;

        }

좋은 웹페이지 즐겨찾기