A Pen by Atsushi Yamamoto on CodePen.
Created
March 27, 2016 05:54
-
-
Save jimmythai/ebc4830d0873c1474210 to your computer and use it in GitHub Desktop.
getQueryparameters
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
| (($) => { | |
| $.getQueryParameters = function(qString = location.search) { | |
| const str = qString.replace(/(^\?)/, ''); | |
| const arr = str.split('&'); | |
| const obj = {}; | |
| for (let i = 0, len = arr.length; i < len; i++) { | |
| arr[i] = arr[i].split('='); | |
| obj[arr[i][0]] = arr[i][1]; | |
| } | |
| return obj; | |
| }; | |
| })(jQuery); | |
| var queryParams = $.getQueryParameters('?a=1&b=10&c=100'); | |
| console.log(queryParams); |
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
| <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment