/ Published in: JavaScript

URL: http://pjotor.com
Since I'm doing this from time to time, I thought I'd put a snipplet here.
This function returns a JSON objectbased on document.location.search
Expand |
Embed | Plain Text
function searchToJSON(){ var rep = {'?':'{"','=':'":"','&':'","'}; var s = document.location.search.replace( /[\?\=\&]/g, function(r){ return rep[r]; } ); return JSON.parse( s.length? s+'"}' : "{}" ); }
You need to login to post a comment.