jQuery Mobile pageinit event
Example
Pop up a message when the page is initialized and enhanced:
$(document).on("pageinit",function(){
alert("pageinit event triggered!")
});
Try it »
Definition and Usage
This event is deprecated after version 1.4.0, use pagecreate as a replacement.
The pageinit event is triggered after the page is initialized and after jQuery Mobile has finished enhancing the page content.
Use this event in place of the jQuery DOM ready event, because it can be triggered whether the page is loaded directly or via an Ajax call.
Note: This event can only be triggered once per page - when the page is first loaded, jQuery Mobile caches the page in the DOM (memory), so when you navigate back from a second page to the first page through the browser, this event will not be triggered, because the first page has already been initialized.
Related events:
- pagebeforecreate - Triggered when the page is initialized and before jQuery Mobile starts enhancing the page.
- pagecreate - Triggered after the page is successfully created, but before the page is enhanced.
Syntax
Trigger all page events in jQuery Mobile:
$("document").on("pageinit",function(event){...})
Try it
Trigger a specified page event:
$("document").on("pageinit","
page
",function(event){...})
Try it
| Parameters | Description |
|---|---|
| function(event) | Required. Specifies the function to execute after the pageinit event is triggered |
函数是一个包含任何jQuery事件属性的可选事件对象 (例如 event.target, event.type, 等)。参阅 [jQuery 事件参考手册](/jquery/jquery-ref-events.html) 查看更多jQuery事件属性。 |
| page | Optional. Used to specify the page id on which the pagebeforecreate event is triggered. For internal pages, please use #id. For external pages, use * externalfile.html.* |
More examples
pagebeforecreate, pagecreate event demo.
This example demonstrates the triggering of the pagebeforecreate, pagecreate events.
Event Object
Use the event.type property to return the type of event that was triggered.
jQuery Mobile Events