Possible Duplicate:
Get query string values in JavaScript
I know you could do this by echoing the variable $_GET['whatevervariable'] to a js variable.i was just wondering if there are other methods that can also do this?
Possible Duplicate:
Get query string values in JavaScript
I know you could do this by echoing the variable $_GET['whatevervariable'] to a js variable.i was just wondering if there are other methods that can also do this?
This will provide the entire $_GET array to your JavaScript app:
<script type="text/javascript"><!--
_GET = <?php echo json_encode($_GET); ?>;
--></script>
The $_GET
superglobal is just an array of the querystring.
You can fetch the querystring in javascript with window.location.search
, but to use it like $_GET
will need some sort of parsing and usually a few regular expressions to handle difficult characters etc.
Just try var qs = window.location.search;
and then figure out exactly what you need, and how you will get it.
The easy solution if doing it inline is just echoing $_GET into a variable, like in danorton's answer.