Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <h1>Update:</h1> <h2>jQuery Mobile 1.4</h2> </blockquote> <h3>The following events are deprecated and will be removed on jQuery Mobile 1.5:</h3> <ol> <li><p><a href="http://api.jquerymobile.com/pageshow/" rel="nofollow noreferrer"><code>pageshow</code></a></p> <ul> <li>Replacement: <a href="http://api.jquerymobile.com/pagecontainer/#event-show" rel="nofollow noreferrer"><code>pagecontainershow</code></a></li> <li><p>Usage: It is used to retrieve <code>id</code> of previous page.</p> <pre><code>$(document).on("pagecontainershow", function (e, ui) { var previous = ui.prevPage; }); </code></pre></li> <li><p>This event cant be attached to a specific <em>page ID</em>.</p></li> <li>Recommendation: Use <a href="http://api.jquerymobile.com/pagebeforeshow/" rel="nofollow noreferrer"><code>pagebeforeshow</code></a> instead to attach event to specific pages. <blockquote> <p><strong><a href="http://jsfiddle.net/Palestinian/YTj23/" rel="nofollow noreferrer">Demo</a></strong></p> </blockquote></li> </ul></li> <li><p><a href="http://api.jquerymobile.com/pagehide/" rel="nofollow noreferrer"><code>pagehide</code></a></p> <ul> <li>Replacement: <a href="http://api.jquerymobile.com/pagecontainer/#event-hide" rel="nofollow noreferrer"><code>pagecontainerhide</code></a></li> <li><p>Usage: It is used to retrieve <code>id</code> of next page.</p> <pre><code>$(document).on("pagecontainerhide", function (e, ui) { var next = ui.nextPage; }); </code></pre></li> <li><p>This event cant be attached to a specific <em>page ID</em>.</p></li> <li>Recommendation: Use <a href="http://api.jquerymobile.com/pagebeforehide/" rel="nofollow noreferrer"><code>pagebeforehide</code></a> instead to attach event to specific pages. <blockquote> <p><strong><a href="http://jsfiddle.net/Palestinian/YTj23/" rel="nofollow noreferrer">Demo</a></strong></p> </blockquote></li> </ul></li> <li><p><a href="http://api.jquerymobile.com/pageinit/" rel="nofollow noreferrer"><code>pageinit</code></a></p> <ul> <li>Replacement: <a href="http://api.jquerymobile.com/pagecreate/" rel="nofollow noreferrer"><code>pagecreate</code></a></li> </ul></li> </ol> <hr> <blockquote> <h2>jQuery Mobile 1.3.2 and below</h2> <p><sup><em>Some events are deprecated, check update</em></sup></p> </blockquote> <h3>Introduction:</h3> <p>jQuery Mobile uses Ajax navigation to load pages/views into DOM (pagecontainer), enhance (style) them and then display them on request. A page goes through many steps (page events) from the time it gets inserted into DOM until it's removed. This applies to both models, <em>Single-Page</em> and <em>Multi-Page</em>.</p> <h3>Events:</h3> <p>I will go through essential events and most used ones in their sequential order.</p> <ul> <li><p><code>mobileinit</code>: <sup>(1)</sup></p> <p>The very first event that fires when a website using jQM is loaded. jQM consists of many widgets that have default options. Those widgets are not initiated during that event, therefore, you can override <em>Global Settings</em> / <em>defaults</em> of those <em>widgets</em> once this event fires.</p> <blockquote> <p><strong>Important:</strong> Your code should go after jQuery.js and before jQM.js to successfully change defaults.</p> </blockquote> <pre><code>&lt;script src="jQuery.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).on("mobileinit", function () { $.mobile.page.prototype.options.theme = "b"; // set theme "b" to all pages }); &lt;/script&gt; &lt;script src="jQuery-Mobile.js"&gt;&lt;/script&gt; </code></pre></li> <li><p><code>pagebeforecreate</code> and <code>pagecreate</code>: <sup>(1)</sup></p> <p>These events are almost the same. During them <em>widgets</em> auto-initialize and start enhance contents markup. They are useful to override <em>widget</em>'s defaults of a specific element(s). </p> <pre><code>$(document).on("pagecreate", "[data-role=page]", function () { $(".selector").listview({ icon: "star" }); // changes list items icons to "star" }); </code></pre></li> <li><p><code>pageinit</code>: <sup>(1)</sup> <sup>(4)</sup></p> <p>This is similar to <code>.ready()</code> and it fires once per page when it's fully initialized and styled but still not viewed. Use it to bind events to that page being initialized. If you don't specify a page, you will get muliple events every time <code>pageinit</code> occurs.</p> <pre><code>$(document).on("pageinit", "#myPage" , function () { $(this).on("swipeleft", function () { // code }); }); </code></pre></li> <li><p><code>pagebeforechange</code>: <sup>(2)</sup></p> <p>It fires twice for a page that not has been viewed before and once for a cached/viewed page. It omits an object of data <code>toPage</code> and <code>options</code>, they contain all details related to the page that will be viewed. It's very useful to know the user came from page <strong>X</strong> and going to page <strong>Y</strong>. During this event, you can prevent the user from viewing page <strong>Y</strong> and take him to page <strong>Z</strong>.</p> <pre><code>$(document).on("pagebeforechange", function (e, data) { if(data.toPage[0].id == "Y") { $.mobile.changePage("Z"); e.preventDefault(); // don't update $.mobile.urlHistory } }); </code></pre></li> <li><p><code>pagebeforehide</code>: <sup>(3)</sup></p> <p>It triggers on the current active page <strong>X</strong> but before page transition / animation takes place.</p></li> <li><p><code>pagebeforeshow</code>: <sup>(3)</sup></p> <p>It triggers on the page <strong>Y</strong> that will be shown after the current page but still no transition / animation.</p></li> <li><p><code>pageshow</code>: <sup>(3)</sup> <sup>(4)</sup></p> <p>Transition / animation is done and page <strong>Y</strong> is shown.</p></li> <li><p><code>pagehide</code>: <sup>(3)</sup> <sup>(4)</sup></p> <p>Transition / animation is done on page <strong>X</strong> and it's hidden.</p></li> </ul> <blockquote> <p><strong><a href="http://jsfiddle.net/Palestinian/SjPLn/" rel="nofollow noreferrer">Demo</a></strong></p> </blockquote> <hr> <h3>Diagrams (jQM 1.4) <sup>(5)</sup></h3> <blockquote> <p><img src="https://i.stack.imgur.com/aUlJs.png" alt="Multi-Page Model"></p> </blockquote> <hr> <blockquote> <p><img src="https://i.stack.imgur.com/AptHD.png" alt="Single Page Model"></p> </blockquote> <p><sup>(1) Fires once.</sup></p> <p><sup>(2) Fires twice for new page and once for cached page.</sup></p> <p><sup>(3) Fires whenever it occurs.</sup></p> <p><sup><strong>(4) <em>Deprecated</em> as of jQM 1.4 and will be <em>removed</em> on jQM 1.5</strong></sup></p> <p><sup>(5) Resource: PageContainer Events <a href="http://jqmtricks.wordpress.com/2014/03/26/jquery-mobile-page-events/" rel="nofollow noreferrer">link 1</a> &amp; <a href="http://jqmtricks.wordpress.com/2014/05/23/jquery-mobile-page-events-extra/" rel="nofollow noreferrer">link 2</a></sup></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload