Posted By

dubogii on 05/17/11


Tagged

url Vairables


Versions (?)

Get URL Variables


 / Published in: JavaScript
 

URL: http://css-tricks.com/snippets/javascript/get-url-variables/

  1. function getQueryVariable(variable)
  2. {
  3. var query = window.location.search.substring(1);
  4. var vars = query.split("&");
  5. for (var i=0;i<vars.length;i++) {
  6. var pair = vars[i].split("=");
  7. if(pair[0] == variable){return pair[1];}
  8. }
  9. return(false);
  10. }
  11.  
  12. ---------------------------------------------------------------------------------
  13.  
  14. Usage
  15.  
  16. Example URL:
  17.  
  18. http://www.example.com/index.php?id=1&image=awesome.jpg
  19.  
  20. Calling getQueryVariable("id") - would return "1".
  21. Calling getQueryVariable("image") - would return "awesome.jpg".

Report this snippet  

You need to login to post a comment.