Copyright 2025

The Valley of Code

A Flavio Copes project

How to get the fragment part of a URL
Learn how to get the value of the fragment portion of a URL

I’ve had the need to programmatically access the fragment part of a URL, the part of the URL after the # hash symbol.

For example if the URL is index.html#second I want second back.

Here’s how I did it:

const fragment = window.location.hash

Join my AI Workshop !

The Web Development BOOTCAMP cohort starts in February 2026