Answers for "javascript new url"

0

javascript new url

const url = new URL(url [, base])
// KEEP IN MIND that new URL(...) adds the first parameter to the second one

// examples:

// Base urls
let m = 'https://developer.mozilla.org';

new URL('en-US/docs', m); 
// => 'https://developer.mozilla.org/en-US/docs'
// adds the first parameter to second one

new URL('/en-US/docs', "https://developer.mozilla.org/fr-FR/toto");
// => 'https://developer.mozilla.org/en-US/docs'
// the / in start of '/en-US/docs' makes the link start from base and ignore other routes

new URL('en-US/docs', "https://developer.mozilla.org/fr-FR/toto");
// => 'https://developer.mozilla.org/fr-FR/en-US/docs'
// this time the url starts from the last route, then it adds first parameter to it

new URL('http://www.example.com', m);
// => 'http://www.example.com/'
// first param replaces second one because it has it's own origin
Posted by: Guest on June-14-2021

Code answers related to "javascript new url"

Code answers related to "Javascript"

Browse Popular Code Answers by Language