获取和设置URL里星号(#)的参数

示例:http://gzmsg.com/go/news.aspx#page=12

var DF = {};
(function () {
    var a = function () {
        var d, e = {},
		b;
        d = window.location.hash.replace(/^#/, "");
        if (d == "") {
            this.uhash = {}
        } else {
            d = d.split("|");
            for (var c = 0; c < d.length; c++) {
                b = d[c].split("=");
                e[b[0]] = b[1]
            }
            this.uhash = e
        }
    };
    a.prototype.set = function (e) {
        var d = [];
        if (arguments.length == 1 && /Object/.test(Object.prototype.toString.call(e))) {
            for (var c in e) {
                if (e.hasOwnProperty(c)) {
                    this.uhash[c] = e[c]
                }
            }
            for (var b in this.uhash) {
                d.push(b + "=" + this.uhash[b])
            }
            window.location.hash = d.join("|")
        } else {
            logger.info("设置hash的参数不正确")
        }
    };
    a.prototype.get = function (b) {
        if (arguments.length == 1) {
            return this.uhash[b]
        } else {
            return this.uhash
        }
    };
    DF.URLHash = new a()
})();

设置:var a = DF.URLHash.get("page");

获取:var b = DF.URLHash.set("page");

原文地址:https://www.cnblogs.com/sntetwt/p/3337446.html