Skip to content

The URL Object

New Course Coming Soon:

Get Really Good at Git

Find out what is a URL object and how to use it

URL is a namespace used to host 2 static methods used to manipulate URLs using Blobs:

Given a blob, you generate a URL to it using the URL.createObjectURL() function:

const myURL = URL.createObjectURL(aBlob)

Once you have the blob URL, you can destroy it from memory using:

URL.revokeObjectURL(myURL)

In addition to this, URL offers a very different functionality through its constructor, which can be used to create a URL. You can call it like this:

const currentUrl = new URL(window.location.href)

Now currentUrl has a set of properties you can use to inspect the URL:

which are the usual parts of a URL.

You can alter any of those, except origin and searchParams which are read only, and generate a new URL string by calling the toString() method, or by referencing the href property.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Read my DOM Tutorial on The Valley of Code
→ Read my Browser Events Tutorial on The Valley of Code
→ Read my Browser APIs Tutorials on The Valley of Code

Here is how can I help you: