Possible Duplicate:
How can I get query string values?
Lets say, we have a <script> tag like this in the HTML markup
<script src="/path/file.js?test=1&data=2"></script>
..is there any way to access the query-string within file.js ? window.location does not change of course, so you can’t use that for that.
If this is not possible, how can you pass data into a script file ?
Musa has the right approach here (from the comments). You can access the script tag like any other (you can use an ID to make it easy):
Then just parse out the src and grab only the query string:
Note: I’m using split for simplicity’s sake. You might want to use regex.
If you want reload the js file, just reset the source:
I think that should work in most browsers.
Alternately, as others have mentioned, you might want to write more flexible functions or use global variables to achieve what you’re trying to do through _GET vars.