js获取页面名称

function pageName() {
    var strUrl = location.href;
    var arrUrl = strUrl.split("/");
    var strPage = arrUrl[arrUrl.length - 1];
    if (strPage.indexOf("?") >= 0)
    {
        strPage = strPage.split('?')[0];
    }
    return ReplaceAll(strPage, "#", "");
}

function ReplaceAll(str, sptr, sptr1)
{
    while (str.indexOf(sptr) >= 0) {
        str = str.replace(sptr, sptr1);
    }
    return str;
}

原文地址:https://www.cnblogs.com/loveheyi/p/5082208.html