www.mywebsite.com/?foo=bar
How can I get the value of foo into a Javascript variable?
www.mywebsite.com/?foo=bar
How can I get the value of foo into a Javascript variable?
You don't even need PHP for that. Basically, you can parse window.location.href
to get the value of a GET URL parameter into a JavaScript variable.
There is plenty of code online, you can use for example this:
function getUrlParameter( 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];
}
To get the value of foo
, just call getUrlParameter("foo")
in your JavaScript code.