Js验证userAgent是否来自手机端

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return (r[2]); return null;
}
var openId = GetQueryString("openId");
var index = GetQueryString("index");
function IsWapPage() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    var bIsWP = sUserAgent.match(/windows phone/i) == "windows phone";
    //var IsWap = (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsWP);
    //return IsWap;
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsWP) {
        switch (index) {
            case "Authorization": window.location.href = "Authorization.html?openId=" + openId; break;
            case "ReportExcption": window.location.href = "ReportExcption.html?openId=" + openId; break;
            case "ExcptionDetails": window.location.href = "ReportRecord.html?openId=" + openId; break;
            default: break;
        }
    } else {
        window.location.href = "ErrorWarning.html";
    }
}
时间: 2024-11-09 03:27:01

Js验证userAgent是否来自手机端的相关文章

js实现双指缩放图片 手机端双指缩放图片

首先引入js文件,需要jq,pinchzoom.js.pinchzoom.js需要在jq环境下使用,可以 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes

使用JS进行pc端、手机端判断

<script type="text/javascript">            (function(){                var ua = navigator.userAgent.toLowerCase();                var bIsIpad = ua.match(/ipad/i) == "ipad";                var bIsIphoneOs = ua.match(/iphone os/i) 

js检测到如果是手机端就跳转到手机端的网址代码

if((/AppleWebKit.*Mobile/i.test(navigator.userAgent)||/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))&&window.location.href.indexOf("?mob

js判断PC端还是手机端

if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { window.location.href = "手机版网址"; } else { window.location.href = "PC端网址"; }   原文地址:https://www.cnblogs.com/go-wandering/p/8658566.html

js判断浏览设备是 手机端,电脑端还是平板端

console.log(navigator.userAgent); var os = function() { var ua = navigator.userAgent, isWindowsPhone = /(?:Windows Phone)/.test(ua), isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, isAndroid = /(?:Android)/.test(ua), isFireFox = /(?:Firefox)/

JS 绑定数据,实现手机端下拉实现分页 手机下拉分页(MVC)

//在界面设置一个div 将数据动态绑定到这个div里面,在界面加载的时候,调用此方法 $(function(){ //默认进来显示第一页,一页显示五条数据 GetList(1,5); }) function GetList(page,size){ //将动态生成的html代码赋值给tr var tr=""; var url=''; ajaxHelper(url,'GET').done(function(dt){ //获取后台查询过来的数据 var data=eval(dt); $(d

JAVA-判断请求来自PC端还是手机端

某些情形,我们需要判断Http请求是来自手机端还是电脑端,关键是取得User-Agent的信息,进行筛选判断即可. 核心类如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public static boolean  isMobileDevice(String requestHeader){         /**          * android : 所有android设备          * mac os : iphone ipad      

java端判断请求来自pc端还是手机端

记录是为了更好的成长! 在项目中遇到一个问题,需要判断请求是来自pc端还是手机端,如下直接贴代码: /** * 判断请求来自手机端还是电脑端 */ public static boolean isMobileDevice(String requestHeader) { /* * android :所有安卓设备 * mas os :iphone * windows phone :windows系统手机 */ String[] deviceArray = new String[] {"android

《JS实现复制内容到剪贴板功能,可兼容所有PC浏览器,不兼容手机端》

前记:本来原生的JS是有提供一个函数来实现这个功能(window.clipboardData),但是很遗憾,这个函数仅仅支持IE和FF浏览器,所以基本用处不大.下边介绍的是一个第三方插件库(ZeroClipboard.js). ZeroClipboard.js在Git上的地址为:https://github.com/zeroclipboard/zeroclipboard 注意:此js库不支持兼容手机端(包括Android.IOS),仅支持PC端浏览器. 第一步:将插件库引入到工程中. 把Git上