This example demonstrates how to use the Browser History Manager to remember which months have been viewed with the calendar widget and dynamically update it when the user presses the browser's back/forward buttons.
In our example, the calendar widget relies on the following markup:
This markup should be inserted right after the opening body
tag.
In our example, we need the Event Utility, DOM Utility, Calendar Widget, and the Browser History Manager:
In our simple example, we have only one module, represented by the calendar widget. We will refer to this module using the identifier
"calendar". The state of the calendar module will be represented by a string composed of the month and the year the widget currently
renders, separated by "_"
(e.g. "2_2007"
for February 2007)
Use the YAHOO.util.History.getBookmarkedState
method and default to the month corresponding to today's date:
Use the YAHOO.util.History.register
method, passing in the calendar module identifier, the initial state of the calendar
module, and the callback function that will be called when the state of the calendar module has changed:
onReady
method
Use the Browser History Manager onReady
method to instantiate the calendar widget. Also, retrieve the current
state of the calendar module, and use that state to show the right month (the current state may be different from the initial
state under certain circumstances - see the User's Guide)
A new history entry must be added every time the user views a new month. Use the calendar widget's beforeRender
event handler (set to handleCalendarBeforeRender
- see above):
Simply call YAHOO.util.History.initialize
, passing in the id of the input field and IFrame we inserted
in our static markup:
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings