pagebeforeload


pagebeforeload eventversion added: 1.0

Description: Triggered before any load request is made.

  • jQuery( ".selector" ).on( "pagebeforeload", function( event ) { ... } )

Callbacks bound to this event can call preventDefault() on the event to indicate that they are handling the load request. Callbacks that do this *MUST* make sure they call resolve() or reject() on the deferred object reference contained in the data object passed to the callback.

The data object, passed as the 2nd arg to the callback function contains the following properties:

  • url (string)
    • The absolute or relative URL that was passed into $.mobile.loadPage() by the caller.
  • absUrl (string)
    • The absolute version of the url. If url was relative, it is resolved against the url used to load the current active page.
  • dataUrl (string)
    • The filtered version of absUrl to be used when identifying the page and updating the browser location when the page is made active.
  • deferred (object)
    • Callbacks that call preventDefault() on the event, *MUST* call resolve() or reject() on this object so that changePage() requests resume processing. Deferred object observers expect the deferred object to be resolved like this:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      $( document ).on( "pagebeforeload", function( event, data ) {
      // Let the framework know we're going to handle the load.
      event.preventDefault();
      // ... load the document then insert it into the DOM ...
      // at some point, either in this callback, or through
      // some other async means, call resolve, passing in
      // the following args, plus a jQuery collection object
      // containing the DOM element for the page.
      data.deferred.resolve( data.absUrl, data.options, page );
      });

      or rejected like this:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      $( document ).on( "pagebeforeload", function( event, data ) {
      // Let the framework know we're going to handle the load.
      event.preventDefault();
      // ... load the document then insert it into the DOM ...
      // at some point, if the load fails, either in this
      // callback, or through some other async means, call
      // reject like this:
      data.deferred.reject( data.absUrl, data.options );
      });
  • options (object)
    • This object contains the options that were passed into $.mobile.loadPage().