Docs

URL.constructor

Constructs a new URL.

Syntax

new URL(url, base?)

Parameters

Examples

let url = new URL("https://example.com/path?query=value#fragment")
url.hostname
"example.com"
// Relative URL with base
let url = new URL("/api/data", "https://api.example.com")
url.href
"https://api.example.com/api/data"