Menu

How to get a segment from a URL using JS?

We can find a text or get a segment from a URL or web address using the JS split and slice function. Below is an example of a slice and split function in simple JavaScript code.

Lets assume we have a URL: https://rashidjorvee.blogspot.com/content/2015/javascript:getName_function/12032/live.html

When we run the split based on colon(:) it will return as below.

e.g. window.location.href.split(":").pop()

result ==> getName_function/12032/live.html

Now, from this if you want to read only few characters from any index, then do the slice on the URL.

e.g. window.location.href.split(":").pop().slice(0,7);

result ==> getName

1 comment:

  1. Master RamDial is a great and best Indian Astrologer in Texas, who have expertise in solving husband and wife problems. First, he analyzes the mental situation of the affected couple and then analyzes psychologically. After that, analyzing the positions of planets in the horoscope, he provides some powerful mantras and remedies to the couple.

    Famous Indian Astrologer in Texas

    ReplyDelete