停止显示页面 [英] Stop showing page

查看:111
本文介绍了停止显示页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

$(document).on("pagebeforeshow", "#myPage", function(event){ 
  if(condition){
    //I need to do something here to stop loading "myPage"
    ???
    $.mobile.changePage("example.jsp");
   }
   else {
     //continue showing actual page normally
      ...
   }
});

我没有找到任何方法更改为example.jsp页面而不显示myPage像一秒钟。有没有办法做到这一点?我尝试使用像 window.stop() event.stopPropagation()这样的东西,但它不起作用。

I didn't found any way to change to "example.jsp" page without showing "myPage" for like a second. Is there any way to do that? I tried using things like window.stop() and event.stopPropagation() but it doesn't work.

谢谢!

推荐答案

在你的情况下,你需要听 pagebeforechange 要传递的事件 data.toPage 并显示另一个。

In your case, you need to listen to pagebeforechange event to pass showing data.toPage and show another one.

使用 pagebeforehide pagebeforeshow 将显示 data.toPage ,然后跳转到目标页面。

Using pagebeforehide and pagebeforeshow will result in showing data.toPage and then jump to the target page.


演示

Demo



// for demo purposes
var condition = 0;

// triggers when leaving any page
$(document).on("pagebeforechange", function (e, data) {

  // id of page that you want to skip if condition is true/false, it's up to you
  var to_page = data.toPage[0].id;

  // skip showing #myPage if condition is true
  if (to_page == "myPage" && condition == 0) {

    // true! go to p3 instead
    $.mobile.changePage("#p3", {
        transition: "flip"
    });

    /* prevent updating URL history and allow new transition if you want.
       Without this, #myPage will be pushed into $.mobile.urlHistory
       and any new transition (animation) will be neglected */        
    e.preventDefault();
  }
  /* in the demo, if you change condition value, #p2 will be shown
     when condition returns "false". #myPage will be shown normally */
});




注意: pagebeforechange 将开火两次,这是正常的,不要惊慌;)

Note: pagebeforechange will fire twice, it's normal, don't panic ;)

这篇关于停止显示页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆