3

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.

5
  • replace('urlpart2', 'urlpart3')? Commented Nov 7, 2014 at 7:22
  • @dfsq Can I have more details ? May be as an answer section ? Thanks in advance. Commented Nov 7, 2014 at 7:26
  • If you just need to replace specific string urlpart2 you can go with simple replace method: var newUrlPath = urlPath.replace('urlpart2', 'urlpart3'). Try it and see if it's what you need. Commented Nov 7, 2014 at 7:29
  • 1
    var urlPath = window.location.href.replace('urlpart2', 'urlpart3') Commented Nov 7, 2014 at 7:31
  • @dfsq Yes,It's working.Can you put it as an answer.Then I can accept it.Thanks a lot. Commented Nov 7, 2014 at 7:38

1 Answer 1

3

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.