Web APIs

URL.origin

Try the free JavaScript compiler

Returns the serialized origin; ordinary HTTPS origins include scheme, host and port.

Formal Syntax & Structure

javascript syntaxjavascript
url.origin

Return Value

string

Serialized origin, or null string for opaque origin.

Working Example

Example Snippetjavascript
(async () => {const a=new URL("https://example.test/a"),b=new URL("https://example.test:8443/b");console.log(a.origin===b.origin,b.port);})()
JavaScript Reference