Pass parameters to a Script tag - Get Parameters of Current Script Tag Src Let This is Script Tag in your main html and you have to get the value of id parameter in script.js or Get Parameters of Current Script Tag Src or Pass parameters to a Script tag See an Example Below - //Script Tag in Main HTML (i.e. index.html) <script src="script.js?id=WqoYv89"></script> Here is Content of script.js //Content of Script.js let params = new URL(document.currentScript.src); params = params.searchParams; console.log(params.get('id')); Result on Console :- WqoYv89 About UrlSearchParams :- https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get About Document.currentScript :- https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript google tag manager,how to get a variable from another script javascript,script tag,how to access a variable from another html script,script tag api,where should th