-2

I have below url

Input url1 = https://www.example1.com/xyz/abc/123

I need modified above url and replace only domain to https://www.modifiedexample.com/

Output url2= https://www.modifiedexample.com/xyz/abc/123

This should work in all the browser

How to achieve this in Javasript in simple and efficient way

1
  • This didnt fix issue for me Commented Aug 19, 2021 at 12:42

1 Answer 1

0

You can try URL API:

const url = new URL('https://www.example1.com/xyz/abc/123');

url.hostname = 'www.modifiedexample.com';

console.log(url.href); // https://www.modifiedexample.com/xyz/abc/123

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.