Last active
August 29, 2015 13:56
-
-
Save beezly/9186841 to your computer and use it in GitHub Desktop.
Update or set a parameter in querystring found inside an element attribute (useful for changing the parameters to an <img src="blah?foo=true"> attribute)
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
setQueryStringParameter = (element, elementAttr, paramName, paramValue) -> | |
src=element.attr elementAttr | |
splitSrc=src.split '?' | |
uri=splitSrc[0] | |
qs=splitSrc[1] | |
qsObject={} | |
qs.split('&').forEach (attribute) -> | |
split_attr=attribute.split('=') | |
qsObject[split_attr[0]]=split_attr[1] | |
console.log qsObject | |
qsObject[paramName]=paramValue | |
qs=Object.keys(qsObject).map (key) -> key+'='+qsObject[key] | |
src=uri+'?'+qs.join('&') | |
element.attr elementAttr, src |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment