Skip to content

Instantly share code, notes, and snippets.

@sakunyo
Created May 18, 2012 04:55
Show Gist options
  • Save sakunyo/2723229 to your computer and use it in GitHub Desktop.
Save sakunyo/2723229 to your computer and use it in GitHub Desktop.
getSearchQueries.js

#JavaScript .getSearchQueries

リクエストURLから?key=valueを抜き出し、objectを返す。

author: Sakuya Sugo

date: 2012-05-19T00:17:48

var Helper = {};
Helper.getSearchQueries = function(){
var o = {},
i,
item, q;
if( location.search.length ){
q = location.search.substring(1).split("&");
for ( i in q ) {
item = q[ i ].split("=");
o[ item[ 0 ] ] = item[ 1 ];
}
}
return o;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment