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.

1
  • 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. Commented Jul 29, 2013 at 14:22

1 Answer 1

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

var params = $("#my-script").attr("src").split("?")[1];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.