Obtaining query parameters in Javascript

The location object suffers from poor design in Javascript. Here’s a function to retrieve the query parameters from the page (if any).

function getQuery(){     var s = location.search;     var params=Array();     if ( s.length > 0 ) {         s=s.split('?');         s=s[1];         s=s.split('&');         for(i=0;i<s.length;i++){             params.push( s[i].split('=') );         }     }     return params; }

Enjoy, and if you find anything to add or remove, don’t hesitate to let me know in the comments!

Publié le Catégories BlogMots-clés

2 réflexions au sujet de « Obtaining query parameters in Javascript »

  1. Once again, this entry was hard to get through the door, because of escaping less than  entities… I had to edit it from the database!

Les commentaires sont fermés.