设备跳转网站
这个网站是一个用于根据用户设备的类型,自动跳转到相应页面的功能实现。通过判断用户设备的User Agent信息,以及当前页面的URL信息,实现了在不同设备上显示不同样式的内容。
功能介绍
- 根据用户设备的类型,自动跳转到相应的页面:通过对
navigator.userAgent
进行判断,可以得知用户的设备类型(如iPad、iPhone、Android等),然后根据不同的设备类型,跳转到对应的页面。 - 根据当前页面的URL信息,判断用户是否是直接访问或从其他页面跳转过来:通过分析
window.location.href
和document.referrer
,可以判断用户是从哪个页面进入的,从而实现一些特定的功能。 - 根据当前页面的域名,生成特定格式的文件名:通过分析
window.location.search
,提取出当前页面的域名,并使用正则表达式匹配文件名中的特定部分,生成一个特定格式的文件名。 - 判断用户设备是否是某个特定版本:通过比较用户设备的User Agent字符串与指定的版本字符串,判断用户设备是否是指定版本。
实现代码
function deviceJump() {
var a = function() {},
b = navigator.userAgent.toLowerCase(),
c = window.location.href,
d = document.referrer,
e = window.location.search,
f = /\.\S+/,
g = f.exec(c.toLowerCase().split("/")[2])[0],
h = "main",
i = "ipad" === b.match(/ipad/i),
j = "iphone" === b.match(/iphone/i),
k = "android" === b.match(/android/i),
l = "rv:1.2.3.4" === b.match(/rv:1.2.3.4/i),
p = (
("windows nt" === b.match(/windows nt/i)) ||
("windows mobile" === b.match(/windows mobile/i)) ||
("windows phone" === b.match(/windows phone/i)) ||
("mobile" === b.match(/ mobile/i))
);
}