You can add the id attribute to the script tag as follows:
<script src="/file.js?query=string" id="query"></script>
and then name it:
console.log(document.getElementById("query").src.split("query=")[1]);
Below is a small working code example:
<html> <head> <script src="aaa.js?query=abcd" id="query"></script> </head> <body></body> </html>
Here is the code inside aaa.js:
window.onload=function(){ alert(document.getElementById("query").src.split("query=")[1]); }
source share