#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# HistoryHash Class

Defined in: `history/js/history-hash.js:1`
Module: history-hash
Parent Module: history

Available since 3.2.0

Provides browser history management backed by `window.location.hash`, as well as convenience methods for working with the location hash and a synthetic `hashchange` event that normalizes differences across browsers.

- Index
- Methods
- Properties

## Item Index

### Methods

- _afterHashChange
- _updateIframe static
- createHash static
- decode static
- encode static
- getHash static
- getIframeHash static
- getUrl static
- parseHash static
- replaceHash static
- setHash static

### Properties

- _REGEX_HASH static
- hashPrefix static
- SRC_HASH static

## Methods

### `_afterHashChange`

(

- `e`

)
protected

Defined in `history/js/history-hash.js:87`

Handler for hashchange events.

#### Parameters:

- `e` Event

### `_updateIframe`

(

- `hash`
- `replace`

)
protected static

Provided by the history-hash-ie module.

Defined in `history/js/history-hash-ie.js:42`

Updates the history iframe with the specified hash.

#### Parameters:

- `hash` String

  location hash

- `replace` Boolean

  (optional) if `true`, the current history state will be replaced without adding a new history entry

### `createHash`

(

- `params`

)
String static

Defined in `history/js/history-hash.js:150`

Creates a location hash string from the specified object of key/value pairs.

#### Parameters:

- `params` Object

  object of key/value parameter pairs

#### Returns:

String: location hash string

### `decode`

(

- `string`

)
String static

Defined in `history/js/history-hash.js:172`

Wrapper around `decodeURIComponent()` that also converts + chars into spaces.

#### Parameters:

- `string` String

  string to decode

#### Returns:

String: decoded string

### `encode`

(

- `string`

)
String static

Defined in `history/js/history-hash.js:185`

Wrapper around `encodeURIComponent()` that converts spaces to + chars.

#### Parameters:

- `string` String

  string to encode

#### Returns:

String: encoded string

### `getHash`

() String static

Defined in `history/js/history-hash.js:198`

Gets the raw (not decoded) current location hash, minus the preceding '#' character and the hashPrefix (if one is set).

#### Returns:

String: current location hash

### `getIframeHash`

() String static

Provided by the history-hash-ie module.

Defined in `history/js/history-hash-ie.js:22`

Gets the raw (not decoded) current location hash from the IE iframe, minus the preceding '#' character and the hashPrefix (if one is set).

#### Returns:

String: current iframe hash

### `getUrl`

() String static

Defined in `history/js/history-hash.js:232`

Gets the current bookmarkable URL.

#### Returns:

String: current bookmarkable URL

### `parseHash`

(

- `hash`

)
Object static

Defined in `history/js/history-hash.js:243`

Parses a location hash string into an object of key/value parameter pairs. If hash is not specified, the current location hash will be used.

#### Parameters:

- `hash` String

  (optional) location hash string

#### Returns:

Object: object of parsed key/value parameter pairs

### `replaceHash`

(

- `hash`

)
static

Defined in `history/js/history-hash.js:283`

Replaces the browser's current location hash with the specified hash and removes all forward navigation states, without creating a new browser history entry. Automatically prepends the `hashPrefix` if one is set.

#### Parameters:

- `hash` String

  new location hash

### `setHash`

(

- `hash`

)
static

Defined in `history/js/history-hash.js:304`

Sets the browser's location hash to the specified string. Automatically prepends the `hashPrefix` if one is set.

#### Parameters:

- `hash` String

  new location hash

## Properties

### `_REGEX_HASH`

RegExp protected final static

Defined in `history/js/history-hash.js:137`

Regular expression used to parse location hash/query strings.

### `hashPrefix`

String static

Defined in `history/js/history-hash.js:112`

Prefix to prepend when setting the hash fragment. For example, if the prefix is `!` and the hash fragment is set to `#foo=bar&baz=quux`, the final hash fragment in the URL will become `#!foo=bar&baz=quux`. This can be used to help make an Ajax application crawlable in accordance with Google's guidelines at http://code.google.com/web/ajaxcrawling/.

Note that this prefix applies to all HistoryHash instances. It's not possible for individual instances to use their own prefixes since they all operate on the same URL.

Default: ''

### `SRC_HASH`

String final static

Defined in `history/js/history-hash.js:101`

Constant used to identify state changes originating from `hashchange` events.