2980网络邮箱-简而不凡
设备类型检测
该网站使用 detectDeviceType
函数来检测用户的设备类型。根据用户代理字符串(User Agent String)中的特征,判断用户所使用的设备类型并返回相应的结果。
function detectDeviceType() {
var ua = window.navigator.userAgent;
if (ua.match(/(iPad)/) || (window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1)) {
return "ipad";
} else if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)) {
return "h5";
} else {
return "pc";
}
}
上述代码中,首先获取用户代理字符串 ua
,然后通过正则表达式匹配判断设备的类型。如果匹配到 iPad,则返回 "ipad"
;如果匹配到 Android、webOS、iPhone、iPad、iPod、BlackBerry、IEMobile 或者 Opera Mini,则返回 "h5"
,表示是移动端设备;否则返回 "pc"
,表示是非移动端设备。
邮箱跳转移动端页面功能
该网站还实现了一个邮箱跳转移动端页面的功能,使用了 mailType
函数来判断当前页面是否为移动端页面。如果是移动端页面且域名包含 "2925.com"
或者 "mail2.xiyouji.com"
,则返回 true
,表示需要跳转到移动端页面;否则返回 false
,表示不需要跳转。
function mailType() {
return window.location.origin.includes("2925.com") || window.location.origin.includes("mail2.xiyouji.com");
}
使用了 window.location.origin
获取当前页面的域名,并通过字符串的 includes()
方法判断域名是否包含指定的字符串,从而确定是否需要跳转到移动端页面。