Skip to content

Instantly share code, notes, and snippets.

@AlexeyPogorelov
Created January 17, 2017 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexeyPogorelov/aedcaa20b3b0b3771482c1160352cb58 to your computer and use it in GitHub Desktop.
Save AlexeyPogorelov/aedcaa20b3b0b3771482c1160352cb58 to your computer and use it in GitHub Desktop.
// set and get value from href
function hrefValue (key, value) {
'use strict';
var result,
regexp,
replacer,
href = window.location.href;
regexp = new RegExp(key + '=([^\;\&\n]+)');
replacer = function (match, val) {
return match.replace(val, value);
};
result = href.match(regexp);
if (!result) return false;
if (value) {
return href.replace(regexp, replacer);
} else {
return result[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment