How can I change the last component of a url path?

前端 未结 7 861
一整个雨季
一整个雨季 2021-02-09 03:15
\"http://something.com:6688/remote/17/26/172\"

if I have the value 172 and I need to change the url to 175

\"http://something.com:6688/         


        
7条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 04:06

    //Alternative way.

    var str =  window.location.href;
    var lastIndex = str.lastIndexOf("/");
    var path = str.substring(0, lastIndex);
    var new_path = path + "/new_path";
    window.location.assign(new_path);
    

提交回复
热议问题