Skip to content

Instantly share code, notes, and snippets.

@nenjiru
Created October 15, 2010 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenjiru/627537 to your computer and use it in GitHub Desktop.
Save nenjiru/627537 to your computer and use it in GitHub Desktop.
クエリーストリングをハッシュに変換 jQuery Plugin
////////////////////////////////////////////////////////////////////////////////
// Query string convert to hash - jQuery Plugin
// クエリーストリングをハッシュに変換
//
// Copyright 2010, Minoru Nakanow
// Licensed under the MIT licenses.
// http://www.opensource.org/licenses/mit-license.html
//
// Usage:
// $.toObject("index.html?width=500&height=auto");
//
////////////////////////////////////////////////////////////////////////////////
(function($) {
//--------------------------------------------------------------------------
// jQuery extend
//--------------------------------------------------------------------------
jQuery.extend({
/**
* Query string convert to hash
*
* @param {String} string "?"を含んだURLなどの文字列
* @return {Object}
*/
toObject: function(string) {
var result = {};
var query = string.substring(string.indexOf("?")+1);
var param = query.split("&");
for (var i=0; i<param.length; i++) {
var hash = param[i].split("=");
result[hash[0]] = hash[1];
}
return result;
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment