Самый простейший вариант:
function parse_url( url ) {
var parts = url.split( "#" ),
out = {};
out.url = url;
out.hash = ( parts.length > 1 ? ( ( url = parts.shift() ) || 1 ) && parts.join( "#" ) : "" );
url = ( parts = url.split( "?" ) ).shift();
out.search = parts.join( "?" );
out.scheme = ( parts = url.split( "://" ) ) && parts.length > 1 ? parts.shift() : "";
out.host = ( ( parts = parts.join( "://" ).split( "/" ) ) && parts.length > 1 &&
parts[0].indexOf(".") > 0 || out.scheme ) && parts.shift() || "";
out.script = parts.pop();
out.path = ( parts.length > 0 ? "/" : "" ) + parts.join( "/" );
return out;
}
var out = parse_url( prompt( "Введите URL: ", "http://somesite.com/folder/index.php?param=value#lalala" ) );
alert([
"url: " + out.url,
"scheme: " + out.scheme,
"host: " + out.host,
"path: " + out.path,
"script: " + out.script,
"search: " + out.search,
"hash: " + out.hash
].join("\n"));