Posted By

agdm on 02/25/11


Tagged

url javascript parameters


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

aspawn


mapping of url parameters


 / Published in: JavaScript
 

given a url:

http://www.someurl.com/page.html?param1=foo&param2=bar

You can use map.param1 outside of the function such as:

$('#some_hidden_field').val(map.param1);

  1. var map = {};
  2. function getUrlVars() {
  3. var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. map[key] = value;
  5. });
  6. return map;
  7. }
  8.  
  9. getUrlVars();
  10.  
  11. console.log(map.param1);
  12. console.log(map.param2);

Report this snippet  

You need to login to post a comment.