How to bind to jquery-mobile pagebeforeload event?

放肆的年华 提交于 2019-12-13 01:19:57

问题


I'm getting desperate trying to get the jQuery mobile pagebeforeload event to fire. This just does nothing:

 $(document).on("pagebeforeload", function( e, data ) {
        console.log("hello");
    });

According to the JQM docs, the syntax is correct. Still, nothing happens. Can anybody tell me why that is?


回答1:


Make sure you're including preventDefault(); Otherwise, it'll just merrily continue loading.

Docs: http://jquerymobile.com/demos/1.1.0/docs/api/events.html

$( document ).bind( "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 );

});



回答2:


Your code worked for me exactly as it is.

Be sure to note that this will only work if you are loading a separate page. It will not work for internally linked pages because it is not actually loading a page.



来源:https://stackoverflow.com/questions/10181698/how-to-bind-to-jquery-mobile-pagebeforeload-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!