这是一个用于获取页面URL参数的JavaScript函数。它通过document.location.search
获取当前URL的查询字符串,然后使用正则表达式匹配指定参数名的值。如果匹配成功,它会尝试解码该值并返回。
var getParam = function(name){
var search = document.location.search;
var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
var matcher = pattern.exec(search);
var items = null;
if(null != matcher){
try{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
}catch(e){
try{
items = decodeURIComponent(matcher[1]);
}catch(e){
items = matcher[1];
}
}
}
return items;
};
代码还检查了用户代理字符串中是否包含特定的设备标识符,以确定当前设备是否为iPad、iPod或iPhone。如果是移动设备,is_mobi
变量将被赋值为true
,否则为false
。