Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get everything before the hash from the address bar with Javascript?

I know I can get the hash value directly with this bit of code:

var hash = window.location.hash;

But is there anyway I can get the everything before the hash value directly as well?

Thank you!

Edit Using the Answer bellow: I am guessing the best way is..

var pageAddress = window.location.split('#')[0];
like image 999
Mohammad Avatar asked Sep 17 '11 18:09

Mohammad


People also ask

How do you hash in JavaScript?

You can implement a Hash Table in JavaScript in three steps: Create a HashTable class with table and size initial properties. Add a hash() function to transform keys into indices. Add the set() and get() methods for adding and retrieving key/value pairs from the table.

How do I know if a URL has a hash?

The task is to check whether an URL contains or not. This can be done by using the Location hash property in JavaScript. It returns the string which represents the anchor part of a URL including the hash '#' sign.


1 Answers

I use:

window.location.href.replace(window.location.hash, '');
like image 137
Saeed Neamati Avatar answered Oct 08 '22 14:10

Saeed Neamati