Skip to content

Allow URL: toString() on window.location.href #12

@gerarts

Description

@gerarts

Allow the use of

window.location.href = url.toString();

when url is an instance of URL as encoding is already handled.

See URL Standard > 6.1 URL class

See URL Standard > 6.2 URLSearchParams class

// URL with UTF-8 in path
const url = new URL('/path/шеллы', 'https://example.com');

console.log(url.toString());
// Output: "https://example.com/path/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
const url = new URL('/', 'https://example.com');

// Add param with UTF-8 content
url.searchParams.set('some', 'шеллы');

console.log(url.toString());
// Output: "https://example.com/?some=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions