0

I am able to get data from a URL with the following structure -

http://mydomain.com/test.php?word=hello

Using PHP I would use the following

$word = $_GET["word"];

Can anyone tell me if it is possible to achieve the same thing but using JavaScript?

Thanks

2 Answers2

0

Yes, it is possible:

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

Source: Get URL Parameters Using Javascript

Sascha Galley
  • 15,711
  • 5
  • 37
  • 51
0

You can get these values using window.location.search. You can either roll your own code to parse this or use something like the answers to this question.

Community
  • 1
  • 1
Manu Clementz
  • 1,807
  • 12
  • 19