Created
March 13, 2009 15:47
-
-
Save anfedorov/78623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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