PopClip JavaScript API Reference
    Preparing search index...

    Class URL

    Parses a URL string into its components, and builds URL strings from components. This is the standard Web API URL class: MDN documents it in further depth, though only the members declared here are guaranteed to be present.

    The component properties may be assigned to modify the URL in place; each assignment updates href, percent-encoding characters where the URL syntax requires it. Use searchParams to read and edit the query string.

    Instances may be passed directly to PopClip.openUrl and PopClip.share.

    const url = new URL("https://example.com/docs?q=hello#top");
    print(url.host); // example.com
    print(url.pathname); // /docs
    url.searchParams.set("q", "goodbye");
    url.hash = "";
    print(url.href); // https://example.com/docs?q=goodbye
    Index
    • Parses a URL from a string. Throws a TypeError if the result is not a valid URL.

      Parameters

      • url: string

        The URL string. May be relative if base is given.

      • Optionalbase: string | URL

        A base URL to resolve url against.

      Returns URL

    hash: string

    The fragment, with its leading # — e.g. "#top". Empty string if the URL has no fragment.

    host: string

    The hostname, plus : and the port if one is specified — e.g. "example.com:8080".

    hostname: string

    The hostname alone, without the port — e.g. "example.com".

    href: string

    The whole URL as a string. Assigning to it replaces the entire URL, throwing a TypeError if the new value cannot be parsed.

    origin: string

    The scheme, hostname and port — e.g. "https://example.com:8080".

    password: string

    The password given before the hostname. Empty string if there is none.

    pathname: string

    The path, beginning with / — e.g. "/docs/index.html".

    port: string

    The port number as a string — e.g. "8080". Empty string if no port is specified or it is the default for the scheme.

    protocol: string

    The scheme, with its trailing : — e.g. "https:".

    search: string

    The query string, with its leading ? — e.g. "?q=hello". Empty string if the URL has no query. Assigning replaces the whole query.

    searchParams: URLSearchParams

    A live URLSearchParams view of the query string. Changes made through it are reflected in search and href.

    username: string

    The username given before the hostname. Empty string if there is none.

    • Returns href. (Called by JSON.stringify().)

      Returns string

    • Returns href.

      Returns string