<script src="myscript.js?someParameter=123"></script>
From within myscript.js
, is there any way to obtain that someParameter
was set to 123
? Or is the only way to use server side scripts that generate the javascript file with the parameters in it?
Jquery Address does this, so i've been checking their code out and this is the improved solution I just created myself:
I hope this does what you need?
Well, you get URL parameters from
window.location.href
. As the name says, it refers to the current window. What the<script>
tag does it to embed the linked file into the current document, thus into the same window. If you parsedwindow.location.href
from the linked JavaScript file, you'd only get the URL from the embedding document.There are two ways to pass parameters to another JavaScript file:
window
instance.