当前位置:网站首页>JS judge the PC end or mobile end
JS judge the PC end or mobile end
2022-04-22 06:42:00 【Bring in the red moon】
Method 1 :
function is_Mobile() {
var Arry = ["iPhone", "iPad", "Android", "Windows Phone", "BB10; Touch", "BB10; Touch", "PlayBook", "Nokia"];
var ua = navigator.userAgent;
var res = Arry .filter(function(arr) {
return ua.indexOf(arr) > 0;
});
return res.length > 0;
}
// return ture or false,true Indicates the mobile terminal ,false Indicates that it is not a mobile terminal
Method 2 :
function is_Mobile() {
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";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
return true
} else {
return false
}
}
// return ture or false,true Indicates the mobile terminal ,false Indicates that it is not a mobile terminal
// Determine whether it is wechat
function is_WeiXin () {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
}
}
Method 3 :
var browser={
versions:function(){
var u = navigator.userAgent, app = navigator.appVersion;
return {// Mobile terminal browser version information
trident: u.indexOf('Trident') > -1, //IE kernel
presto: u.indexOf('Presto') > -1, //opera kernel
webKit: u.indexOf('AppleWebKit') > -1, // Apple 、 Google kernel
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, // Firefox kernel
mobile: !!u.match(/AppleWebKit.*Mobile.*/), // Is it a mobile terminal
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android Terminal or uc browser
iPhone: u.indexOf('iPhone') > -1 , // Is it iPhone perhaps QQHD browser
iPad: u.indexOf('iPad') > -1, // whether iPad
webApp: u.indexOf('Safari') == -1, // whether web It should be programmed , No head and bottom
weixin: u.indexOf('MicroMessenger') > -1, // Wechat or not
qq: u.match(/\sQQ/i) == " qq" // whether QQ
};
}(),
language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
if(browser.versions.mobile || browser.versions.ios || browser.versions.android ||
browser.versions.iPhone || browser.versions.iPad){
//web End
}else if(browser.versions.weixin){
// WeChat
}else{
//PC End
}
// Judge whether it is IE
function isIE() {
if (!!window.ActiveXObject || "ActiveXObject" in window){
return true;
}else{
return false;
}
}
版权声明
本文为[Bring in the red moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220556231169.html
边栏推荐
猜你喜欢

MySQL——索引

A series of interpretations of the general data protection regulations (gdpr): how to judge whether offshore enterprises are under the jurisdiction of gdpr?

ArcGIS 基于TIN地表面数据和建筑数据进行视域分析

从零开始学安卓(kotlin)二——Activity

MySQL在面试中经常被问到的经典问题。

从零开始学安卓(kotlin)五——UI

从零开始学安卓(kotlin)一 ——入门

OLAP和OLTP的区别及所对应模型(基础知识)

Iframe child parent pass parameter

小程序调用扫描二维码功能并跳转到二维码指定的路径
随机推荐
kubectl命令自动补齐
uniapp解决首页点击返回(手机返回键)跳到登录页
calendar.getActualMaximum(calendar.DAY_OF_MONTH)的坑点
Open source database management systems are now more popular than commercial products
MYSQL事务之事务隔离级别
在微信小程序中打开的页面不能超过10个,达到10个页面后,就不能再打开新的页面
Wechat applet interface encapsulation (uniapp)
点击触发其他dom元素:< $refs,$el >
Shumei technology has obtained the international certification of ISO / IEC 27701 privacy information management system
Pixel手机电信4G破解(含解锁BL和root)
EXCEL 利用替换、分列、填充功能综合整理财务数据
正则验证
创新实训(九)整合
使用@Autowired出现Field injection is not recommended
PostgreSQL 13.3, 12.7, 11.12, 10.17 and 9.6.22 have been released!
mysql5.7.x 数据授权导致1141
Solve the problem of error in installing PostgreSQL under windows2012 R2
Click to trigger other DOM elements: < $refs, $El >
小程序定时任务的多种写法
MySQL is a classic question often asked in an interview.