Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a 'class' that does this and here it is:</p> <pre><code>function QS(){ this.qs = {}; var s = location.search.replace( /^\?|#.*$/g, '' ); if( s ) { var qsParts = s.split('&amp;'); var i, nv; for (i = 0; i &lt; qsParts.length; i++) { nv = qsParts[i].split('='); this.qs[nv[0]] = nv[1]; } } } QS.prototype.add = function( name, value ) { if( arguments.length == 1 &amp;&amp; arguments[0].constructor == Object ) { this.addMany( arguments[0] ); return; } this.qs[name] = value; } QS.prototype.addMany = function( newValues ) { for( nv in newValues ) { this.qs[nv] = newValues[nv]; } } QS.prototype.remove = function( name ) { if( arguments.length == 1 &amp;&amp; arguments[0].constructor == Array ) { this.removeMany( arguments[0] ); return; } delete this.qs[name]; } QS.prototype.removeMany = function( deleteNames ) { var i; for( i = 0; i &lt; deleteNames.length; i++ ) { delete this.qs[deleteNames[i]]; } } QS.prototype.getQueryString = function() { var nv, q = []; for( nv in this.qs ) { q[q.length] = nv+'='+this.qs[nv]; } return q.join( '&amp;' ); } QS.prototype.toString = QS.prototype.getQueryString; //examples //instantiation var qs = new QS; alert( qs ); //add a sinle name/value qs.add( 'new', 'true' ); alert( qs ); //add multiple key/values qs.add( { x: 'X', y: 'Y' } ); alert( qs ); //remove single key qs.remove( 'new' ) alert( qs ); //remove multiple keys qs.remove( ['x', 'bogus'] ) alert( qs ); </code></pre> <p>I have overridden the toString method so there is no need to call QS::getQueryString, you can use QS::toString or, as I have done in the examples just rely on the object being coerced into a string. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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