Created
May 1, 2016 15:41
-
-
Save sebin/180f07a4d83a6511291001ca285f559e to your computer and use it in GitHub Desktop.
update url parameter function
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
function updateURLParameter(url, param, paramVal) | |
{ | |
var TheAnchor = null; | |
var newAdditionalURL = ""; | |
var tempArray = url.split("?"); | |
var baseURL = tempArray[0]; | |
var additionalURL = tempArray[1]; | |
var temp = ""; | |
if (additionalURL) | |
{ | |
var tmpAnchor = additionalURL.split("#"); | |
var TheParams = tmpAnchor[0]; | |
TheAnchor = tmpAnchor[1]; | |
if(TheAnchor) | |
additionalURL = TheParams; | |
tempArray = additionalURL.split("&"); | |
for (i=0; i<tempArray.length; i++) | |
{ | |
if(tempArray[i].split('=')[0] != param) | |
{ | |
newAdditionalURL += temp + tempArray[i]; | |
temp = "&"; | |
} | |
} | |
} | |
else | |
{ | |
var tmpAnchor = baseURL.split("#"); | |
var TheParams = tmpAnchor[0]; | |
TheAnchor = tmpAnchor[1]; | |
if(TheParams) | |
baseURL = TheParams; | |
} | |
if(TheAnchor) | |
paramVal += "#" + TheAnchor; | |
var rows_txt = temp + "" + param + "=" + paramVal; | |
return baseURL + "?" + newAdditionalURL + rows_txt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment