Created
October 15, 2010 03:07
-
-
Save nenjiru/627537 to your computer and use it in GitHub Desktop.
クエリーストリングをハッシュに変換 jQuery Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////// | |
// 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