Stop showing page

后端 未结 4 1990
后悔当初
后悔当初 2020-11-30 15:19

I want to do something like this:

$(document).on(\"pagebeforeshow\", \"#myPage\", function(event){ 
  if(condition){
    //I need to do something here to sto         


        
4条回答
  •  北海茫月
    2020-11-30 16:23

    Tested and working:

    html

    Index page

    Second page

    Third page

    jquery

    $(document).on('pagebeforechange', function(e, data){  
        var to = data.toPage;
        var from = data.options.fromPage;
    
        if (typeof to  === 'string') {
            var u = $.mobile.path.parseUrl(to);
            to = u.hash || '#' + u.pathname.substring(1);
            if (from) from = '#' + from.attr('id');
    
            if (from === '#index' && to === '#second') {
                e.preventDefault();
                e.stopPropagation();            
                $.mobile.changePage( "#third");
            }
        }
    });
    

    jsfiddle

    http://jsfiddle.net/tronc/GPUay/3/

提交回复
热议问题