# Yahoo! UI Library

### history 3.3.0

Yahoo! UI Library > history > HistoryHash
Search:
Filters Show Private Show Protected Show Deprecated

## Class HistoryHash - extends HistoryBase

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.

### Constructor

HistoryHash `( config )`

Parameters:
  `config <Object>` (optional) Configuration object. See the HistoryBase documentation for details.

### Properties

#### _REGEX_HASH - `protected static final RegExp`

Regular expression used to parse location hash/query strings.

#### hashPrefix - `static String`

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 Value: ''

#### SRC_HASH - `static final String`

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

#### Properties inherited from HistoryBase:

`_config, _initialState`

### Methods

#### _afterHashChange

`protected void _afterHashChange ( e )`
Handler for hashchange events.

Parameters:
  `e <Event>`

#### _updateIframe

`protected static void _updateIframe ( hash , replace )`
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

`static String createHash ( params )`
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

`static String decode ( string )`
Wrapper around `decodeURIComponent()` that also converts + chars into spaces.

Parameters:
  `string <String>` string to decode

Returns: `String`
  decoded string

#### encode

`static String encode ( string )`
Wrapper around `encodeURIComponent()` that converts spaces to + chars.

Parameters:
  `string <String>` string to encode

Returns: `String`
  encoded string

#### getHash

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

Returns: `String`
  current location hash

#### getUrl

`static String getUrl ( )`
Gets the current bookmarkable URL.

Returns: `String`
  current bookmarkable URL

#### parseHash

`static Object parseHash ( hash )`
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

`static void replaceHash ( hash )`
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

`static void setHash ( hash )`
Sets the browser's location hash to the specified string. Automatically prepends the `hashPrefix` if one is set.

Parameters:
  `hash <String>` new location hash

#### Methods inherited from EventTarget:

`_getType, _monitor, _parseType, addTarget, after, before, bubble, detach, detachAll, fire, getEvent, getTargets, on, once, parseType, publish, removeTarget, subscribe, unsubscribe, unsubscribeAll`

#### Methods inherited from HistoryBase:

`_change, _defChangeFn, _fireChangeEvent, _fireEvents, _fireRemoveEvent, _init, _isSimpleObject, _resolveChanges, _storeState, add, addValue, get, replace, replaceValue`

#### Events inherited from HistoryBase:

`[key]Change, [key]Remove, history:change,`

Copyright © 2011 Yahoo! Inc. All rights reserved.