Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created March 13, 2009 15:47
Show Gist options
  • Save anfedorov/78623 to your computer and use it in GitHub Desktop.
Save anfedorov/78623 to your computer and use it in GitHub Desktop.
var loc;
(function locdef() {
function findParam(name) {
return new RegExp(name + '=([^&#]*)');
}
loc = {
updateParam : function updateParam(name, val) {
var l = location.href,
s = name + '=' + val;
return location.href = l.match(findParam(name)) ? l.replace(findParam(name), s) :
l.match(/\?/) ? l.replace(/\?/, '?' + s + '&') :
l.match(/#/) ? l.replace(/#/, '?' + s + '#') :
l + '?' + s;
},
getParam : function getParam(name) {
return (location.href.match(findParam(name))||{})[1] || "";
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment