Created
May 13, 2019 09:21
-
-
Save rc1021/3703bb284e05d97faf5e0fec834c733d to your computer and use it in GitHub Desktop.
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
function queryStringToJson(s="") | |
{ | |
return JSON.parse(s.replace(/[?|&]([A-Za-z0-9]*)=([^&]*)/ig, ",\"$1\":\"$2\"").slice(1).replace(/(.*)/, "{ $1 }")); | |
} |
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
// url like https://www.your.domain/pathname?p=2&act=delete&type=photo&id=0001 | |
var queryObject = queryStringToJson(location.search); | |
console.log(queryObject); | |
// result: | |
// {p: "2", act: "delete", type: "photo", id: "0001"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment