W3cubDocs

/jQuery Mobile

navigate

navigate eventversion added: 1.3

Description: A wrapper event for both hashchange and popstate

The navigate event is a wrapper around both the hashchange and popstate events. In addition to providing a single event for all browsers it also provides a data object in both cases allowing for the unification of handlers. This feature is used by the $.mobile.navigate method to include directionality and URL information.

Example:

Change the hash fragment twice then log the data provided with the navigate event when the browser moves backward through history. NOTE: The state will not be provided by default in browsers that only support hashchange. For that functionality please see the navigate method docs.

// Bind to the navigate event
$( window ).on( "navigate", function( event, data ) {
  console.log( data.state );
});
 
// Trigger a navigate event by pushing state
window.history.pushState( { foo: "bar" }, "Title", "http://example.com/#foo" );
 
// From the `navigate` binding on the window, console output:
// => {}
 
// Trigger a navigate event by pushing state
window.history.pushState( {}, "Title", "http://example.com/#bar" );
 
// From the `navigate` binding on the window, console output:
// => {}
 
// Trigger a navigate event by moving backward through history
window.history.back();
 
// From the `navigate` binding on the window, console output:
// => { foo: "bar" }

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquerymobile.com/navigate