jQuery Mobile pagebeforeloadEvent

jQuery Mobile 事件jQuery Mobile Events

Example

Show an alert message before the load request:

$(document).on("pagebeforeload",function(){
alert("pagebeforeload event triggered!");
});

Try it Yourself »

Definition and Usage

The pagebeforeload event is triggered before any loading occurs.

Related events:

  • pageload- Triggered when a page is successfully loaded and inserted into the DOM.
  • pageloadfailed- Triggered after a page fails to load.

Note:When an external page is loaded into the DOM, two types of events are always triggered: the pagebeforeload event before loading, and after loading either pageload (success) or pageloadfailed (failure).


Syntax

$("document").on("pagebeforeload",function(event,data){...})

Parameter Description
function(event,data) Required. Specifies the function to execute when the pagebeforeload event is triggered.

This function contains the following two parameters:

Event object- Includes any jQuery event properties (event.target, event.type, etc.). For more information, see thejQuery Event Reference Manual

Data object- Contains the following types:

  • url(string) - An absolute or relative URL passed to $.mobile.loadPage() via the callback
  • absUrl(string) - An absolute reference containing the URL
  • dataUrl(string) - Contains the browser's URL location
  • deferred(object) - Contains resolve() or reject()
  • options(object) - Contains options to be sent to $.mobile.loadPage()
Note:A callback function that calls preventDefault() for this event must call the resolve() or reject() method for this event, so that the changePage() request can resume.


实例

More Examples

Related Events Demo
This example demonstrates pageload and pageloadfailed.

Event object
Use the event.type property to return the type of event triggered.

Data object
Use data.url to return the URL of the external page.


jQuery Mobile 事件jQuery Mobile Events

Other Extensions