/* Parse URL address parsurl ( url ) .file; // = ' index.html ' Parsurl ( url ) .hash; // = ' top ' parsurl ( url ) .host; // = ' www.abc.com ' parsurl ( url ). query; // = '? Id=255&m=hello ' parsurl ( url ). queryurl // = ' Id=255&m=hello ' parsurl ( url ) .params; // = object = { id: 255, m: hello } parsurl ( url ) .prefix; // = ' www ' parsurl ( url ) .path; // = '/dir/index.html ' parsurl ( url ). segments; // = array = [' dir ', ' index.html '] parsurl ( url ) .port; // = ' 8080 ' &nbSp; parsurl ( url ) .protocol; // = ' http ' parsurl ( url ). source; // = ' Http://www.abc.com:8080/dir/index.html?id=255&m=hello#top ' * /function parsurl ( 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 = {},seg = a.search.replace (/^\?/, "). Split (' & '),len = seg.length, i = 0, s; for (; i<len;i++) { if (!seg[i]) { continue; } s = seg[i].split (' = '); ret[s[0]] = s[1]; } return ret; }) (), Queryurl:a.search.replacE (/^\?/, '), Prefix: a.hostname.split ('. ') [0],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 ('/')}; }
Explain and get the parameters in the URL address