I have a url like result?graphType=default&product=xyzzzz&shop=11
I just want to change value of graphType, when user clicks a button.
On click of that button i store some value in a variable, and i want to replace graphType=default with graphType=my_new_value
in my url without reload.
I don't understand how to split url at graphType= .
and even if I am able to split to url at graphType, how can I replace default (which can be something else as well depending on user options) with my variable
I have a url like result?graphType=default&product=xyzzzz&shop=11
I just want to change value of graphType, when user clicks a button.
On click of that button i store some value in a variable, and i want to replace graphType=default with graphType=my_new_value
in my url without reload.
I don't understand how to split url at graphType= .
and even if I am able to split to url at graphType, how can I replace default (which can be something else as well depending on user options) with my variable
- Check here stackoverflow./questions/7171099/… – Hitesh Misro Commented Aug 4, 2016 at 6:10
-
You could start with
window.location.search
to return any url parameters... – NewToJS Commented Aug 4, 2016 at 6:10 -
url without reload
: as soon as you change the URL; browser will reload it. Its a part of URL which you are going to change and hence reload. Its not in your hand. – vijayP Commented Aug 4, 2016 at 6:15
1 Answer
Reset to default 7I think your solution should be like this
$(document).ready(function(){
var queries = {};
$.each(document.location.search.substr(1).split('&'), function(c,q){
var i = q.split('=');
queries[i[0].toString()] = unescape(i[1].toString()); // change escaped characters in actual format
});
// modify your parameter value and reload page using below two lines
queries['your key']='your value';
document.location.href="?"+$.param(queries); // it reload page
//OR
history.pushState({}, '', "?"+$.param(queries)); // it change url but not reload page
});