0

First, I will include the script in my HTML.

<script type="text/javascript" src="test.js?param=value"></script>

Second, I want my script to act based on value of param. I was not able to find any concrete answer to this question. Is it possible this way?

Something crossed my mind but I didn't tried it because I didn't like the idea so much: Maybe I could search whole HTML with JQuery, find that string and get the parameter but maybe there is something in JQuery that could help me solve this in more convenient way.

  • One solution is to have a server-side language process your JS file. Like `test.php?param=value`, then add `var param = '=$_GET['param']?>';` into your file. – gen_Eric Jul 29 '13 at 14:22

1 Answers1

0
<script id="my-script" type="text/javascript" src="test.js?param=value"></script>

var params = $("#my-script").attr("src").split("?")[1];
John
  • 5,942
  • 3
  • 42
  • 79