/ Published in: JavaScript
given a url:
>`http://www.someurl.com/page.html?param1=foo¶m2=bar`
You can use map.param1 outside of the function such as:
>`$('#some_hidden_field').val(map.param1);`
>`http://www.someurl.com/page.html?param1=foo¶m2=bar`
You can use map.param1 outside of the function such as:
>`$('#some_hidden_field').val(map.param1);`
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var map = {}; function getUrlVars() { var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { map[key] = value; }); return map; } getUrlVars(); console.log(map.param1); console.log(map.param2);