Skip to content

Instantly share code, notes, and snippets.

@tarikul05
Last active December 13, 2017 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarikul05/a2271e7ece8b37420b2e685a5dc85793 to your computer and use it in GitHub Desktop.
Save tarikul05/a2271e7ece8b37420b2e685a5dc85793 to your computer and use it in GitHub Desktop.
Change current page query string with jquery.
function getQueryVariable(url, variable) {
var queryString = url.substring(1);
var index = queryString.indexOf("?");
var vars = queryString.substr(index+1).split('&');
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
function newUrl(FLD,VAL) {
var currentUrl = window.location.href;
var currentVal = getQueryVariable(currentUrl,FLD);
return location.href.replace(FLD+"="+currentVal, FLD+"="+VAL);
}
// call funcitons with pages query string
newUrl('page','4')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment