当前位置: 代码迷 >> .NET新技术 >> 如何用JS获取获取浏览器地址栏参数
  详细解决方案

如何用JS获取获取浏览器地址栏参数

热度:76   发布时间:2016-04-25 01:32:11.0
怎么用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;
}
  相关解决方案