Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append url part into main url using angularjs or javascript

I have a url path as shown below.

http://localhost:12534/urlpart1/urlpart2?querystring=140

So I need to replace the "urlpart2" with the "urlpart3" by using javascript or anugularjs.How can I do that.I can get the whole url by using:

  var urlPath = window.location.href;

Any help would be highly appreciated.

like image 326
Sampath Avatar asked Jul 24 '26 13:07

Sampath


1 Answers

If you just need to replace specific substring urlpart2 you can go with simple replace method:

var urlPath = window.location.href;
var newUrlPath = urlPath.replace('urlpart2', 'urlpart3');
like image 152
dfsq Avatar answered Jul 26 '26 04:07

dfsq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!