最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Modify a parameter in url with page reload using jsjquery - Stack Overflow

programmeradmin2浏览0评论

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

Share Improve this question edited Aug 4, 2016 at 6:08 Farkhat Mikhalko 3,6653 gold badges25 silver badges38 bronze badges asked Aug 4, 2016 at 6:03 IshitaIshita 871 gold badge2 silver badges10 bronze badges 3
  • 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
Add a ment  | 

1 Answer 1

Reset to default 7

I 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
});
发布评论

评论列表(0)

  1. 暂无评论