request url variables with javascript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function request(value)
  2. {
  3. var queryStr = location.href.split('?');
  4. if (queryStr.length < 2){ return ""; }
  5. var requestObj = {};
  6. var level1 = [];
  7. level1 = queryStr[1].split('&');
  8. for (var i = 0; i < level1.length; i++) {
  9. level2 = level1[i].split('=');
  10. requestObj[level2[0]] = level2[1];
  11. }
  12. return decodeURIComponent(requestObj[value]);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.