Posted By

fengelz on 06/29/10


Tagged

url javascript request


Versions (?)

request url variables with javascript


 / Published in: JavaScript
 

  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  

You need to login to post a comment.