js判断pc还是mobile访问

来源:互联网 发布:java中get(class) 编辑:程序博客网 时间:2024/06/05 04:49
<%    /* *     *功能:支付宝手机网页支付调试入口页面     *版本:3.3     *日期:2012-08-17     *说明:     *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。     */%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>    <head>    <%    String path = request.getContextPath();    String basePath = request.getScheme() + "://"            + request.getServerName() + ":" + request.getServerPort()            + path + "/";    %>    <title>测试入口判断</title>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script type="text/javascript" src="jquery-1-7-2.js"></script><script type="text/javascript">    $(document).ready(function(){        var browser = {                versions : function() {                    var u = navigator.userAgent, app = navigator.appVersion;                    return {//移动终端浏览器版本信息                                                                             trident : u.indexOf('Trident') > -1 && u.indexOf('Mobile') == -1, //IE内核  ,支持IE8以上版本                                               //    presto : u.indexOf('Presto') > -1, //oprea的pc输出不是这个判断                                                webKit : u.indexOf('AppleWebKit') > -1 && u.indexOf('KHTML') > -1, //苹果、谷歌内核 、opera内核  、360内核                                                       gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核                                                    mobile : !!u.match(/AppleWebKit.*Mobile.*/)   //是否为移动终端                            || (!!u.match(/AppleWebKit/) && u.indexOf('KHTML') == -1)                            || (u.indexOf('Trident') > -1 && u.indexOf('Mobile') > -1)   //诺基亚                            || (u.indexOf('Opera') > -1 && u.indexOf('KHTML') == -1)   //opera                            || (!!u.match(/AppleWebKit/) && u.indexOf('Android') > -1),  //针对一些国内平板自带浏览器  参数中没有MObile(苹果自带的有)                                       ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端                                     android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器                                                     iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器                                        iPad: u.indexOf('iPad') > -1, //是否iPad                           webApp : u.indexOf('Safari') == -1,//是否web应该程序,没有头部与底部                    google:u.indexOf('Chrome')>-1                };            }(),            language : (navigator.browserLanguage || navigator.language).toLowerCase()            }                        /*            document.writeln("userAgent: "+navigator.userAgent);                    document.writeln("语言版本: "+browser.language);            document.writeln(" 是否为移动终端: "+browser.versions.mobile);            */                if(browser.versions.mobile){            //移动端            window.location.href="<%=basePath%>phonePay/index.jsp" ;        }else{            //pc端            window.location.href="<%=basePath%>pcPay/index.jsp" ;        }            });</script></head><body></body></html>

0 0
原创粉丝点击