<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?
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.hreffrom 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:
windowinstance.