+1 vote

you need an http(s)://google.com:8080/folder/folder/file.php?param1=param1&param2=param2#hash

In the address may not be available domain and therefore the Protocol also may be or may not be directory can be a file or can be applied CNC can be present but may not have the options and the hash.

at the exit you need to get ["http","google.com:8080","/folder/folder/","file.php","param1=param1&param2=param2","hash"]
Avoid regexps, my advice to you. Specialized functions much better.

1 Answer

+8 votes
You can use the properties of the element <a>
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";

parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
little input to split half of that, you can use system variables
such as host request URI , Protocol,het also it is possible to grab. The question specifically why and which part of the url you are going to take. Maybe you invent the wheel. Tell me what you need from the url and let zadnipru options URLs
If the task table so I would have asked. And so I ask how to implement it with the help of the regular season
Beautiful, damn it!