Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're using jQuery, you can use a library, such as <a href="http://benalman.com/projects/jquery-bbq-plugin/" rel="noreferrer">jQuery BBQ: Back Button &amp; Query Library</a>.</p> <blockquote> <p>...jQuery BBQ provides a full <code>.deparam()</code> method, along with both hash state management, and fragment / query string parse and merge utility methods.</p> </blockquote> <p>Edit: Adding Deparam Example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code> var DeparamExample = function() { var params = $.deparam.querystring(); //nameofparam is the name of a param from url //code below will get param if ajax refresh with hash if (typeof params.nameofparam == 'undefined') { params = jQuery.deparam.fragment(window.location.href); } if (typeof params.nameofparam != 'undefined') { var paramValue = params.nameofparam.toString(); } };</code></pre> </div> </div> </p> <p>If you want to just use plain JavaScript, you could use...</p> <pre class="lang-js prettyprint-override"><code>var getParamValue = (function() { var params; var resetParams = function() { var query = window.location.search; var regex = /[?&amp;;](.+?)=([^&amp;;]+)/g; var match; params = {}; if (query) { while (match = regex.exec(query)) { params[match[1]] = decodeURIComponent(match[2]); } } }; window.addEventListener &amp;&amp; window.addEventListener('popstate', resetParams); resetParams(); return function(param) { return params.hasOwnProperty(param) ? params[param] : null; } })();​ </code></pre> <p>Because of the new HTML History API and specifically <code>history.pushState()</code> and <code>history.replaceState()</code>, the URL can change which will invalidate the cache of parameters and their values.</p> <p>This version will update its internal cache of parameters each time the history changes.</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