function
changeParamByName(href, paramName, newVal) {
var
tmpRegex =
new
RegExp(
"("
+ paramName +
"=)[a-z]+"
,
'ig'
);
return
href.replace(tmpRegex,
'$1'
+newVal);
}
var
href = changeParamByName(
"http://domain.com?var=thisIsOld&bca=something&b=2&c=3"
,
"bca"
,
"theNewValue"
);
console.log(href);
Reference:
http://blog.adrianlawley.com/jquery-change-url-parameter-value/
if bca=this is title
ReplyDeletethen it'll only replace this word