function parseURL (url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function () {
            var ret = {};
            var seg = window.location.search.replace(/^\?/, '').split('&');
            var s;
            seg.forEach(function (item, index) {
                if (!item) {
                    return;
                }
                s = seg[index].split('=');
                ret[s[0]] = s[1];
            });
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
};

相关文章:

  • 2021-09-19
  • 2021-12-21
  • 2021-10-06
  • 2021-07-07
  • 2022-12-23
  • 2021-05-26
猜你喜欢
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-12-31
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案