js 读取url 参数

来源:互联网 发布:淘宝购物评级怎么看 编辑:程序博客网 时间:2024/06/15 19:44



function getUrlParameters(parameter, staticURL, decode)
{
    /*
    Function: getUrlParameters
    Description: Get the value of URL parameters either from
    current URL or static URL
    Author: Tirumal
    URL: www.code-tricks.com
    */
    var currLocation = (staticURL.length) ? staticURL : window.location.search,
       parArr = currLocation.split("?")[1].split("&"),
       returnBool = true;

    for (var i = 0; i < parArr.length; i++)
    {
        parr = parArr[i].split("=");
        if (parr[0] == parameter)
        {
            return (decode) ? decodeURIComponent(parr[1]) : parr[1];
            returnBool = true;
        } else
        {
            returnBool = false;
        }
    }

    if (!returnBool) return false;
}

0 0