js获取浏览器参数

获取url参数对象(?号后的参数)

function parseQueryString() 
{
    var query = document.location.search.substring(1);
    var parts = query.split('&');
    var params = {};
    for (var i = 0, ii = parts.length; i < ii; ++i) {
        var param = parts[i].split('=');
        var key = param[0].toLowerCase();
        var value = param.length > 1 ? param[1] : null;
        params[decodeURIComponent(key)] = decodeURIComponent(value);
    }
    return params;
}

根据名称,获取参数值

// 根据参数名称获取值,如果获取不到值,返回false
function getParam(name){
    var params = parseQueryString();
    return (name in params ? params[name] : false);
}

你可能感兴趣的:(js获取浏览器参数)