Posted By

CJness on 05/03/11


Tagged

get javascript parameters


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dop3


Javascript function $_GET


 / Published in: JavaScript
 

  1. function get()
  2. {
  3. var get = new Object();
  4. var parameters = window.location.toString().split("?").pop().split("&");
  5.  
  6. for (var i in parameters)
  7. {
  8. var parts = parameters[i].split("=");
  9.  
  10. get[""+parts[0]+""] = parts[1];
  11. }
  12.  
  13. return get;
  14. }
  15.  
  16. //http://www.example.com/?foo=bar&bar=foo
  17. var get = get();
  18.  
  19. console.log(get.foo) // returns "bar"

Report this snippet  

You need to login to post a comment.