How to add parameters to a URL that already contains other parameters and maybe an anchor

后端 未结 9 750
逝去的感伤
逝去的感伤 2020-12-05 19:36

I\'m wondering how I can add a new parameter to an existing url. The problem is: the url may also contain an anchor.

For example:

http://www.example         


        
9条回答
  •  Happy的楠姐
    2020-12-05 20:23

    Something like this ?

    var param = "x=y";
    var split = url.split('#');
    url = split[0] + '&' + param + "#" + split[1];
    

提交回复
热议问题