Created
April 21, 2012 09:55
-
-
Save joshdavenport/2436282 to your computer and use it in GitHub Desktop.
Reload the current page with specified query string variables
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
| function reloadWithQueryStringVars (queryStringVars) { | |
| var existingQueryVars = location.search ? location.search.substring(1).split("&") : [], | |
| currentUrl = location.search ? location.href.replace(location.search,"") : location.href, | |
| newQueryVars = {}, | |
| newUrl = currentUrl + "?"; | |
| if(existingQueryVars.length > 0) { | |
| for (var i = 0; i < existingQueryVars.length; i++) { | |
| var pair = existingQueryVars[i].split("="); | |
| newQueryVars[pair[0]] = pair[1]; | |
| } | |
| } | |
| if(queryStringVars) { | |
| for (var queryStringVar in queryStringVars) { | |
| newQueryVars[queryStringVar] = queryStringVars[queryStringVar]; | |
| } | |
| } | |
| if(newQueryVars) { | |
| for (var newQueryVar in newQueryVars) { | |
| newUrl += newQueryVar + "=" + newQueryVars[newQueryVar] + "&"; | |
| } | |
| newUrl = newUrl.substring(0, newUrl.length-1); | |
| window.location.href = newUrl; | |
| } else { | |
| window.location.href = location.href; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment