1var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search
1function parseUrl(url) {
2 var m = url.match(/^(([^:\/?#]+:)?(?:\/\/((?:([^\/?#:]*):([^\/?#:]*)@)?([^\/?#:]*)(?::([^\/?#:]*))?)))?([^?#]*)(\?[^#]*)?(#.*)?$/),
3 r = {
4 hash: m[10] || "", // #asd
5 host: m[3] || "", // localhost:257
6 hostname: m[6] || "", // localhost
7 href: m[0] || "", // http://username:password@localhost:257/deploy/?asd=asd#asd
8 origin: m[1] || "", // http://username:password@localhost:257
9 pathname: m[8] || (m[1] ? "/" : ""), // /deploy/
10 port: m[7] || "", // 257
11 protocol: m[2] || "", // http:
12 search: m[9] || "", // ?asd=asd
13 username: m[4] || "", // username
14 password: m[5] || "" // password
15 };
16 if (r.protocol.length == 2) {
17 r.protocol = "file:///" + r.protocol.toUpperCase();
18 r.origin = r.protocol + "//" + r.host;
19 }
20 r.href = r.origin + r.pathname + r.search + r.hash;
21 return r;
22};
23parseUrl("http://username:password@localhost:257/deploy/?asd=asd#asd");
1var reg = /.+?\:\/\/.+?(\/.+?)(?:#|\?|$)/;
2var pathname = reg.exec( 'http://www.somedomain.com/account/search?filter=a#top' )[1];
3