Receive URL parameter by JS (jQuery)

1

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

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

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

    
asked by anonymous 06.01.2016 / 14:00

1 answer

1

How do you want the value after the last slash, 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 index starts at zero) to get it from the bar.

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