如何使用javascript更改地址的某些部分并导航到该地址?

时间:2018-04-09 11:24:53

标签: javascript

例如,如果我要改变什么 -

www.site.com/img-small-1.jpg

www.site.com/img-large-1.jpg

我怎么能用javascript做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以使用替换来更改地址

var currentAddress = "www.site.com/img-small-1.jpg";
var newAddress = currentAddress.replace("img-small-1.jpg", "img-large-1.jpg");
window.location.href = newAddress; // this will redirect to new address