Javascript function $_GET


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.