Last active
September 22, 2017 21:59
-
-
Save ugurhasar/89720d40265f72f08b6a97073d53df0d to your computer and use it in GitHub Desktop.
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
JavaScript QueryString Fonksiyonu |
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 queryString() | |
{ | |
var dictionary = []; | |
var queryStr = location.search.substring(1,location.search.length).replace(/(%20|\+)/g,' '); | |
var queries = queryStr.split('&'); | |
for (i = 0; i < queries.length; i++) { | |
var key = ''; | |
var value = ''; | |
if(queries[i].indexOf('=') > -1) | |
{ | |
key = queries[i].substring(0, queries[i].indexOf('=')); | |
value = queries[i].substring(queries[i].indexOf('=') + 1, queries[i].length); | |
} | |
else | |
key = queries[i]; | |
if(arguments.length > 0 && key == arguments[0]) | |
return value; | |
if(!arguments[0]){ | |
dictionary.push({ | |
key: key, | |
value: value | |
}); | |
} | |
} | |
return dictionary.length == 0 ? null : dictionary; | |
} |
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
console.log(queryString('sample')); | |
console.log(queryString('index')); | |
console.log(queryString('id')); |
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
console.log(queryString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment