событие hashchangeверсия добавлена: 1.0
Описание: Включает поддержку истории #hash для закладок.
jQuery( ".selector" ).on( "hashchange", function( event ) { ... } )
Обработчик событий jQuery Mobile .hashchange() позволяет использовать очень простую историю #hash для закладок, предоставляя функцию обратного вызова, связанную с событием window.onhashchange. Событие onhashchange срабатывает при изменении хэша окна.
В браузерах, которые его поддерживают, используется собственное событие HTML5 window.onhashchange. В IE6/7 (и IE8 в режиме совместимости IE7) создаётся скрытый iframe, чтобы обеспечить работу кнопки "Назад" и истории на основе хэша.
Этот плагин расширяет встроенный метод jQuery. Если jQuery Mobile не загружен, вызов метода .hashchange() может не привести к ошибке напрямую, так как метод всё ещё существует. Однако ожидаемое поведение не произойдёт.
$(function() {
// Bind an event to window.onhashchange that, when the hash changes, gets the
// hash and adds the class "selected" to any matching nav link.
$( window ).hashchange(function() {
var hash = location.hash;
// Set the page title based on the hash.
document.title = "The hash is " + ( hash.replace( /^#/, "" ) || "blank" ) + ".";
// Iterate over all nav links, setting the "selected" class as-appropriate.
$( "#nav a" ).each(function() {
var that = $( this );
that[ that.attr( "href" ) === hash ? "addClass" : "removeClass" ]( "selected" );
});
});
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$( window ).hashchange();
}); Источник iframe: example1.html