日期:2014-05-20  浏览次数:20778 次

怎么用JS获取获取浏览器地址栏参数?
http://www.jiayou.in/Login.html#access_token=4c65b3ce696b92e5e5311b6b3c42b8af&expires_in=3600

我想在JS中判断access_token这个值存不存在?
怎么样获取他的值啊?

------解决方案--------------------

function getParam(paramName) {
    paramValue = "";
    isFound = false;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&");
        i = 0;
        while (i < arrSource.length && !isFound) {
            if (arrSource[i].indexOf("=") > 0) {
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                    paramValue = arrSource[i].split("=")[1];
                    isFound = true;
                }
            }
            i++;
        }
    }
    return paramValue;
}