Updating existing URL querystring values with jQuery

前端 未结 9 825
逝去的感伤
逝去的感伤 2020-12-01 16:15

Let\'s say I have a url such as:

http://www.example.com/hello.png?w=100&h=100&bg=white

What I\'d like to do is update the values of

9条回答
  •  [愿得一人]
    2020-12-01 16:33

    My URL is like this: http://localhost/dentistryindia/admin/hospital/add_procedure?hid=241&hpr_id=12

    var reExp = /hpr_id=\\d+/;
    var url = window.location.href;
    url = url.toString(); 
    var hrpid = $("#category :selected").val(); //new value to replace hpr_id
    var reExp = new RegExp("[\\?&]" + 'hpr_id' + "=([^&#]*)"),
    delimeter = reExp.exec(url)[0].charAt(0),
    newUrl = url.replace(reExp, delimeter + 'hpr_id' + "=" + hrpid);
    window.location.href = newUrl;
    

    This is how it worked for me.

提交回复
热议问题