通过 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;
};
posted @ 2018-02-06 12:47  月半流云  阅读(299)  评论(0编辑  收藏  举报