You can use the ‘location.hash’ property in JavaScript to get the hash value (the part of the URL after the “#” symbol) of the current page. For example:
console.log(location.hash);
This will output the current hash value in the browser’s console.
You can also use the ‘.substring()’ method to retrieve the hash value from the ‘window.location.href’ property:
console.log(window.location.href.substring(window.location.href.indexOf("#") + 1));
This will also output the current hash value in the browser’s console.
You can also use the ‘.split()’ method with the “#” separator to retrieve the last element of the array which will be the hash value.
console.log(window.location.href.split("#")[1]);
This will also output the current hash value in the browser’s console.
Also Read:
- What Is a Web Worker In JavaScript?
- How To Sort an Array of Strings In JavaScript?
- ECMAScript vs JavaScript
- What Is Strict Mode In JavaScript?
- Arrow Functions In JavaScript
- Difference Between Node.js and AngularJS With Example
- Difference Between == And === In JavaScript
- What Is JSON In JavaScript
- How To Go Back To Previous Page In JavaScript?
- How To Detect A Mobile Device With JavaScript?
- How To Close The Current Tab In A Browser Window Using JavaScript?
- How To Convert Input Text To Uppercase While Typing Using JavaScript?
- How To Show A Confirmation Message Before Delete In JavaScript?
- How To Detect Browser or Tab Closing In JavaScript?
- How To Get The Name, Size, And Type Of A File In JavaScript?
- Run JavaScript From The Command Line