通过 url 获取相应的 location 信息

var properties = ['href', 'origin', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'];
var getLocation = function(url) {
    var result = {};
    var linkElem = document.createElement('a');
    linkElem.href = url;
    for (var i = 0, len = properties.length; i < len; i++) {
        result[properties[i]] = linkElem[properties[i]];
    }
    return result;
};
原文地址:https://www.cnblogs.com/xiaoyucoding/p/8421775.html