Receive URL parameters by JS (jQuery)

Asked

Viewed 1,042 times

2

I need to capture a parameter from a URL, for example:

http://site.com/paginas/**nome-da-pagina**

I need to capture the page-name with JS or jQuery.

  • I believe there is an answer to that question here at Sopt, here at: http://answall.com/questions/38690/como-pegum-par%C3%A2metro-em-uma-url-e-assign-a-he-a-new-value

  • I am using URL friendly, in this tutorial they use for example: page.php=? page=page-name

1 answer

2


How do you want the value after the last bar, using the location.href and the lastIndexOf function that returns index of the last position of the value that was passed in this case to /. + 1 (because the Indice starts at zero) to pick up from the bar.

var url = location.href.substring(location.href.lastIndexOf('/') + 1)
alert(url);

  • Yes!!! Thank you very much!

  • @Viniciussilva, if Laerte’s answer served you, mark it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.