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
I wrote 21 books to help you become a better developer:
- HTML Handbook
- Next.js Pages Router Handbook
- Alpine.js Handbook
- HTMX Handbook
- TypeScript Handbook
- React Handbook
- SQL Handbook
- Git Cheat Sheet
- Laravel Handbook
- Express Handbook
- Swift Handbook
- Go Handbook
- PHP Handbook
- Python Handbook
- Linux Commands Handbook
- C Handbook
- JavaScript Handbook
- Svelte Handbook
- CSS Handbook
- Node.js Handbook
- Vue Handbook