Web APIs

URL.canParse()

Try the free JavaScript compiler

Test whether URL parsing would succeed. A parseable URL is not necessarily an allowed or reachable destination. Example console output: true false.

Formal Syntax & Structure

javascript syntaxjavascript
URL.canParse(input[, base])

Parameters & Attributes

NameTypeDescription
inputstringAbsolute or relative URL input.
basestringBase URL for relative input.

Return Value

boolean

Whether parsing succeeds.

Working Example

Example Snippetjavascript
console.log(URL.canParse("/items","https://example.invalid"),URL.canParse("/items"));
JavaScript Reference