Last active
December 13, 2017 15:56
-
-
Save tarikul05/a2271e7ece8b37420b2e685a5dc85793 to your computer and use it in GitHub Desktop.
Change current page query string with jquery.
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 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