-4

I have an URL with some parameters.

What is the easiest way to get the url parameter value giving only the end of the parameter string ?

Ex: http://my.domain.com/home?this_is_a_param=5

So, giving to the function :

function returnValueFromURL(url,"param"){
// What I need ...
// return 5;
}

Thanks.

senderos
  • 1
  • 1
  • 2
  • 3
    Please do a little search to see if your question wasn't already asked. It turns out that it was multiple times. Possible duplicate of [Get query string values in JavaScript](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript) – Darin Dimitrov Jan 03 '12 at 22:08
  • possible duplicate: http://stackoverflow.com/questions/2090551/parse-query-string-in-javascript – JohnJohnGa Jan 03 '12 at 22:08
  • possible duplicate of [get URL Parameters from current URL using Prototype JavaScript](http://stackoverflow.com/questions/4467664/get-url-parameters-from-current-url-using-prototype-javascript) – Mike Samuel Jan 03 '12 at 22:09
  • Thanks for the suggestions. But I'm looking for the "this_is_a_param" value with the end of that string (ex : "a_param"). How can I do it? – senderos Jan 03 '12 at 22:11
  • @senderos what? why do you want such things? – JohnJohnGa Jan 03 '12 at 22:13
  • @JohnJohnGa because the URL parameters I get are auto generated and may vary. The only part that doesn't vary is the suffix. – senderos Jan 03 '12 at 22:15

1 Answers1

0

I think i understand what you need:

1- get the query string (document.location.search)

2- split this string by '&', and '='

3- iterate over the array (split result) and just check if the string endsWith 'a_param'

4- then use the function describe here: Parse query string in JavaScript to get the value

Community
  • 1
  • 1
JohnJohnGa
  • 15,446
  • 19
  • 62
  • 87