/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var uri = window.location.href; //http://www.yoururl.com?id=test var queryString = {}; uri.replace( new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3) { queryString[$1] = $3; } ); console.log(queryString['id']); //returns 'test' or 'undefined' if not found
URL: http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/