0

Similar to this question, I would like to get the GET request parameter, but in the script tag itself.

My script tag in HTML <head> is:

<script src="js/script.js?lang=en"></script>

How can I get the lang value ?

jQuery is used and I can obtain the src by:

$('script[src$="/script.js"]').attr('src');
Community
  • 1
  • 1
Raptor
  • 53,206
  • 45
  • 230
  • 366

1 Answers1

1

To obtain the parameters in <script> tag, we can use:

var lang;
var src = $('script[src~="js/script.js"]').attr('src');
if(src != undefined) {
  lang = src.split("lang=")[1] ? src.split("lang=")[1] : 'yourDefaultValue';
}
Raptor
  • 53,206
  • 45
  • 230
  • 366