test:环境测试2

This commit is contained in:
迷和油
2025-06-19 11:34:53 +08:00
parent 8d0aa1bc87
commit f683dfbe26
2 changed files with 135 additions and 31 deletions

View File

@@ -107,20 +107,73 @@
$('.top-country .close-icon').click(function(){ $('.top-country .close-icon').click(function(){
$(".mask,.action-sheet").hide(); $(".mask,.action-sheet").hide();
}) })
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";//判断是否为iPad // 缓存检测结果
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";//判断是否为iPhone用户 let _deviceType = null;
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"; * @returns {'mobile'|'tablet'|'desktop'}
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; */
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; function detectDevice() {
if (_deviceType) return _deviceType;
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
alert("当前是电脑打开") const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
}else{ const screenWidth = window.innerWidth || document.documentElement.clientWidth;
alert("当前是手机打开") const userAgent = navigator.userAgent.toLowerCase();
}
const isTablet =
userAgent.includes('tablet') ||
(userAgent.includes('android') && !userAgent.includes('mobile')) ||
userAgent.includes('ipad') ||
userAgent.includes('kindle');
_deviceType =
isTouch && (screenWidth < 768 || !isTablet) ? 'mobile' :
isTouch && screenWidth >= 768 ? 'tablet' : 'desktop';
return _deviceType;
}
/**
* 显示设备类型提示
*/
function showDeviceAlert() {
const device = detectDevice();
const message = `您正在使用${
device === 'mobile' ? '手机' :
device === 'tablet' ? '平板' : '电脑'
}访问本页面`;
// 使用原生alert
alert(message);
// 或者使用自定义样式的提示需要引入相关CSS
/*
$('<div class="device-alert">' + message + '</div>')
.css({
position: 'fixed',
top: '10px',
right: '10px',
padding: '10px 15px',
background: '#333',
color: 'white',
borderRadius: '5px',
zIndex: '9999'
})
.appendTo('body')
.fadeIn()
.delay(3000)
.fadeOut(function() {
$(this).remove();
});
*/
}
// 页面加载完成后自动检测并提示
$(document).ready(showDeviceAlert);
// 暴露检测方法供外部使用
$.detectDevice = detectDevice;
}) })
</script> </script>

View File

@@ -201,21 +201,72 @@
$('.closecountrybt').click(function () { $('.closecountrybt').click(function () {
$('#top-country').hide(); $('#top-country').hide();
}); });
// 缓存检测结果
var sUserAgent = navigator.userAgent.toLowerCase(); let _deviceType = null;
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";//判断是否为iPad
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";//判断是否为iPhone用户 /**
var bIsMidp = sUserAgent.match(/midp/i) == "midp"; * 检测当前设备类型
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; * @returns {'mobile'|'tablet'|'desktop'}
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; */
var bIsAndroid = sUserAgent.match(/android/i) == "android"; function detectDevice() {
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; if (_deviceType) return _deviceType;
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) { const screenWidth = window.innerWidth || document.documentElement.clientWidth;
alert("当前是电脑打开") const userAgent = navigator.userAgent.toLowerCase();
}else{
alert("当前是手机打开") const isTablet =
} userAgent.includes('tablet') ||
(userAgent.includes('android') && !userAgent.includes('mobile')) ||
userAgent.includes('ipad') ||
userAgent.includes('kindle');
_deviceType =
isTouch && (screenWidth < 768 || !isTablet) ? 'mobile' :
isTouch && screenWidth >= 768 ? 'tablet' : 'desktop';
return _deviceType;
}
/**
* 显示设备类型提示
*/
function showDeviceAlert() {
const device = detectDevice();
const message = `您正在使用${
device === 'mobile' ? '手机' :
device === 'tablet' ? '平板' : '电脑'
}访问本页面`;
// 使用原生alert
alert(message);
// 或者使用自定义样式的提示需要引入相关CSS
/*
$('<div class="device-alert">' + message + '</div>')
.css({
position: 'fixed',
top: '10px',
right: '10px',
padding: '10px 15px',
background: '#333',
color: 'white',
borderRadius: '5px',
zIndex: '9999'
})
.appendTo('body')
.fadeIn()
.delay(3000)
.fadeOut(function() {
$(this).remove();
});
*/
}
// 页面加载完成后自动检测并提示
$(document).ready(showDeviceAlert);
// 暴露检测方法供外部使用
$.detectDevice = detectDevice;
}); });
</script> </script>