title: How do I get query string value from script path?
body: <p>I am adding my Javsacript file in pages with different query strings in the script path like this:</p>
  
  <p>Page1:</p>
  
  <pre><code>&lt;script type="text/javascript" src="file.js?abc=123"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Page2:</p>
  
  <pre><code>&lt;script type="text/javascript" src="file.js?abc=456"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Page3:</p>
  
  <pre><code>&lt;script type="text/javascript" src="file.js?abc=789"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>In my Javascript file, how can I get the value of the "abc" param? I tried using window.location for this, but that does not work.</p>
  
  <p>In case it helps, below is a function I use to find the value of a query string param:</p>
  
  <pre><code>function getQuerystring(key, defaultValue) {
      if (defaultValue == null) defaultValue = "";
      key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regex = new RegExp("[\\?&amp;]" + key + "=([^&amp;#]*)");
      var qs = regex.exec(window.location.href);
      if (qs == null)
          return defaultValue;
      else
          return qs[1];
  }
  </code></pre>