The API
jBookmarker is a very lightweight framework, so it has only a handful of methods - described below - but enough to cover its purpose. If you want to see more code and working examples, see the jBookmarker and Ajax and jBookmarker and Flash pages.
-
jBookmarker.set( key, value )
Saves the "value" into the hash under specified "key"
Example:
jBookmarker.set( 'currentPage', 'about-us' );
-
jBookmarker.get( key )
Retrieves from the hash the value saved under this key. Returns false if the key doesn't exist.
Example
jBookmarker.get( 'currentPage' );
-
jBookmarker.remove( key )
Removes the specified key from the hash along with it's assigned value.
Example
jBookmarker.remove( key )
-
jBookmarker.addListener( pointer )
Adds a callback to be executed everytime the hash string has changed due to an "outside" intervention. If the string is altered by calling jBookmarker.set or jBookmarker.remove, the event is NOT fired. Very useful in detecting if the Back button was clicked.
Example
myCallback = function( oldString, newString ) { alert( 'The string has changed from ' + oldString + ' to ' + newString ); } jBookmarker.addListener( myCallback ); -
jBookmarker.stopListener()
Stops from monitoring changes in the window.location.hash string
Example
jBookmaker.stopListener()
-
jBookmarker.cancelEvent()
Cancels the event and returns the url fragment to its previous state. This function should be used in the callback function.
Example
myCallback = function( oldString, newString ) { var page = jBookmarker.get( 'selectedPage' ) if ( !page ) { // no page is selected, the user must have changed the hash by hand // not cooll jBookmarker.cancelEvent(); } } jBookmarker.addListener( myCallback );