isExternal
Whether a link points to another origin than base: an absolute http(s) URL or a
protocol-relative one (//host/path). Paths, anchors, query strings and non-HTTP schemes
(mailto:, tel:) are never external.
Without base, any absolute or protocol-relative URL counts as external. With a base,
a link to the same origin is internal: same scheme, host and port, the default port of the
scheme (80 for http, 443 for https) being the same as no port. A base with no scheme and
host, or a link with no host, gives false.
It reads the origin from the text and uses no URL global, so it runs on every runtime. A real
URL is accepted as base, as is any object with an href.
Available since v3.1.4
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
url | string | The link to check |
base | string | object | The current origin or page URL to compare with (optional) (optional) |
Returns
Section titled “Returns”boolean — true if the link leaves the origin, false otherwise
Examples
Section titled “Examples”Open external links in a new tab
Section titled “Open external links in a new tab”Compares the link with the current origin: same-origin absolute links stay internal.
Paths and non-HTTP schemes
Section titled “Paths and non-HTTP schemes”Relative paths, anchors, mailto: and tel: are never external; protocol-relative URLs are.
