1var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search
1var reg = /.+?\:\/\/.+?(\/.+?)(?:#|\?|$)/;
2var pathname = reg.exec( 'http://www.somedomain.com/account/search?filter=a#top' )[1];
3