Home >Web Front-end >JS Tutorial >Supplementary documentation on hashchangebroker and statehashable_jquery
url hash: The section after the # number in the URL is usually used to locate an anchor point in the HTML page. Because the page with hash changes will not be refreshed, hash is used to store the script running status in ajax applications, such as gmail's approach.
jquery hash change event plugin: Internet Explorer 8, Firefox 3.6, and Chrome 5 already provide the window.onhashchange event, but this event does not exist in older versions of browsers. This plug-in Use a timer to determine whether the hash has changed, so that the hashchange event can be re-provided in older versions of browsers.
hashchangebroker: I wrote this jquery extend before, which provides four methods:
$.hashchangebroker.subscribe(fragName, handler)
Subscribe to the hash paragraph changes corresponding to fragName and forward it to the specified handler.
URL hash consists of several frags. The format of a frag is: [fragName]:[state]. fragName is the custom hash state name. state is a base64 encoded json string.
Handler has only one parameter state: json format string, describing the custom state.
$.hashchangebroker.publish(hash)
This method should be bound to the window.onhashchange event. Receive the hash and decode it to find the changed frag, and forward it to the handler that subscribes to the frag.
$.hashchangebroker.changeFrag(fragName,state)
This method is called by the statehashable type and is used to modify the state of the frag corresponding to fragName in the hash.
$.hashchangebroker.init()
This method is used to obtain the hash and publish it after the page is refreshed. Just call it in $(document).ready. Should be placed after all subscribe methods.
statehashable: This widget is provided in the hope that it can more conveniently publish the state of the control to the url hash, obtain the state change of the hash fragment corresponding to the control, and trigger the corresponding statechange event.
Usage $(dom).statehashable(); After calling this method, a hashchange event is added to the dom object. When the statehashable object discovers that the hash fragment corresponding to the control has changed, it will trigger the hashchange event of the DOM object.
Usage: