Can I pass a parameter directly to a .js file, and how do I get the value

dom, javascript, parameters

Solution

That's as far only possible by accessing "own" `<script>` element in the HTML DOM and parse the `src` attribute.

Long story short, here's a nice article with detailed explanations and code samples: http://feather.elektrum.org/book/src.html

Problem

I want to pass a parameter to some javascript using a single line of code, like this: ``` <script language="JavaScript" src="courselist.js?subj=MATH" type="text/javascript" /> ``` Inside the javascript file, how can I get the value of the parameter "subj"? Thanks

Original source

Related problems