This question already has an answer here:
If I am on a page such as
http://somesite.com/somepage.php?param1=asdf
In the JavaScript of that page, I would like to set a variable to the value of the parameter in the GET part of the URL.
So in JavaScript:
<script>
param1var = ... // ... would be replaced with the code to get asdf from URI
</script>
What would "..." be?
From my programming archive:
If the value doesn't exist, an empty array is returned.
If the value exists, an array is return that has one item, the value.
If several values with the name exists, an array containing each value is returned.
Examples:
You can use this function
You can get the "search" part of the location object - and then parse it out.
If you're already running a php page then
php bit:
js bit:
But for Html pages Jose Basilio's solution looks good to me.
Good luck!
Here's how you could do it in Coffee Script (just if anyone is interested).