I want to get a specific part of a url between the third and fourth slashes of a link on the page.
EDIT: Sorry I don't think I was clear the first time, I meant getting the specific part of the url OF A LINK found on the page.
I want to get a specific part of a url between the third and fourth slashes of a link on the page.
EDIT: Sorry I don't think I was clear the first time, I meant getting the specific part of the url OF A LINK found on the page.
I'd suggest:
JS Fiddle demo.
The reason we're using
[5]
not[4]
is because of the two slashes at the beginning of the URL, and because JavaScript arrays are zero-based.Here's a working example of getting a particular path segment.
Code:
If you want to do this for the current page, use:
Also, if your url starts with http(s)://, you will need to remove this.
you should elaborate you question and should specify which is your domain, that means on what purpose you are asking that question ??
This may help you:
Then store urlValue as array. then pick up third and forth value of the urlvalue on array.
Usage:
The
replace
makes sure that the first two slashes after the protocol (http
orhttps
) don't count.