Created
January 17, 2017 12:05
-
-
Save AlexeyPogorelov/aedcaa20b3b0b3771482c1160352cb58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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