Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't need jQuery for that purpose. You can use just some pure JavaScript:</p> <pre><code>function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, '\\$&amp;'); var regex = new RegExp('[?&amp;]' + name + '(=([^&amp;#]*)|&amp;|#|$)'), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } </code></pre> <p><strong>Usage:</strong></p> <pre><code>// query string: ?foo=lorem&amp;bar=&amp;baz var foo = getParameterByName('foo'); // "lorem" var bar = getParameterByName('bar'); // "" (present with empty value) var baz = getParameterByName('baz'); // "" (present with no value) var qux = getParameterByName('qux'); // null (absent) </code></pre> <p><br> Note: If a parameter is present several times (<code>?foo=lorem&amp;foo=ipsum</code>), you will get the first value (<code>lorem</code>). There is no standard about this and usages vary, see for example this question: <a href="https://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys">Authoritative position of duplicate HTTP GET query keys</a>.<br> NOTE: The function is case-sensitive. If you prefer case-insensitive parameter name, <a href="https://stackoverflow.com/questions/3939715/case-insensitive-regex-in-javascript">add 'i' modifier to RegExp</a></p> <hr> <p>This is an update based on the new <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams" rel="noreferrer">URLSearchParams specs</a> to achieve the same result more succinctly. See answer titled "<a href="https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#12151322">URLSearchParams</a>" below.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload