How to determine parameters from <script>?

Possible duplicate:
How to get the value of a query string from a script path?

I have:

index.html

...
<script src="myscript.js?param1=1&param2=2">
...

myscript.js:

function getScriptParam(paramName){
  // How to determine the script parameters value?
  var value = HOW TO DO?;

  return value;
}

var param1 = getScriptParam('param1');  // param1 should be '1'

Thank.

+5
source share
1 answer

You CANNOT pass parameters to the myscript.js tag, SCRIPT is used to load only SCRIPT code

You can pass the query string parameter to index.html (for example, index.html? Param1 = 1 & param2 = 2) and then parse the location.search property.

0
source

All Articles