Created
February 7, 2013 07:15
-
-
Save ghoullier/4729135 to your computer and use it in GitHub Desktop.
Provide Simple Class to QueryString
This file contains hidden or 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
(function(global) { | |
var QueryString = (function() { | |
function Class(){ | |
if (this instanceof Class) { | |
} else { | |
throw new Error("Illegal constructor"); | |
} | |
}; | |
Class.get = function(/*String*/name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var pattern = "[\\?&]" + name + "=([^&#]*)", | |
regex = new RegExp(pattern), | |
results = regex.exec(window.location.search); | |
return (results === null) ? "" : global.decodeURIComponent(results[1].replace(/\+/g, " ")); | |
}; | |
return Class; | |
}()); | |
global.QueryString = QueryString; | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment