How To Parse A Url In Javascript

By admin ·
1

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
2

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
3

Further reading

This article expands on this idea to provide a little more functionality.

4

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
5

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
6

Further reading

This article expands on this idea to provide a little more functionality.

7

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
8

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
9

Further reading

This article expands on this idea to provide a little more functionality.

10

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
11

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
12

Further reading

This article expands on this idea to provide a little more functionality.

13

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
14

Create an “a” tag and set the href to the URL you want to parse

Create an “a” tag and set the href to the URL you want to parse:

var parser = document.createElement("a"); parser.href = "http::8000/interests?query=1#bottom";
15

Create an “a” tag and set the href to the URL you want to parse

16

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
17

Now use the parser object to get the URL parts

Now use the parser object to get the URL parts:

parser.protocol; // =>"http:" parser.hostname; // => "howchoo.com" parser.port; // =>"8000" parser.pathname; // => "/interests" parser.search; // => "?query=1" parser.hash; // => "#bottom" parser.host; // => "howchoo.com:8000"
18

Now use the parser object to get the URL parts

19

Further reading

This article expands on this idea to provide a little more functionality.

20

Further reading

This article expands on this idea to provide a little more functionality.

21

Further reading