Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Adds or changes a GET parameter
- * See http://stackoverflow.com/a/13064060/703581
- * Adapted to handle '#' in the URL
- */
- function setGetParameter(paramName, paramValue)
- {
- var url = window.location.href;
- var splitAtAnchor = url.split('#');
- url = splitAtAnchor[0];
- var anchor = typeof splitAtAnchor[1] === 'undefined' ? '' : '#' + splitAtAnchor[1];
- if (url.indexOf(paramName + "=") >= 0)
- {
- var prefix = url.substring(0, url.indexOf(paramName));
- var suffix = url.substring(url.indexOf(paramName));
- suffix = suffix.substring(suffix.indexOf("=") + 1);
- suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
- url = prefix + paramName + "=" + paramValue + suffix;
- }
- else
- {
- if (url.indexOf("?") < 0)
- url += "?" + paramName + "=" + paramValue;
- else
- url += "&" + paramName + "=" + paramValue;
- }
- window.location.href = url + anchor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement