【问题标题】:Change page on certain condition (before current page shows up)在特定条件下更改页面(在当前页面显示之前)
【发布时间】:2012-10-02 04:09:43
【问题描述】:

我想阻止用户访问我的 jqm 页面的子页面。为此,我使用pagebeforecreate 事件来检查某个条件,并根据该条件更改显示的页面(取消当前页面加载并重定向或正常加载当前起始/主页)。问题是,即使我调用preventDefault() 方法,在执行changePage() 之前我仍然看到页面闪烁。我还使用了一个相对 URL 作为changePage(to, options) 的第一个参数(to = 'page.php'),并且由于我的#subpage1 位于page.php 内,它应该打开 - 它确实打开了 - 但随后转换因为没有进行真正的刷新而损坏。

请注意,我有一个 page.php,包括不同的 #subpage(例如 #subpage1#subpage2)。

jQuery(document).on('pagebeforecreate', '#subpage2', function(event, data) {
    if (!isCondition1() && !isCondition2()) {
        // stop loading #subpage2
        event.preventDefault();
        jQuery.mobile.changePage(jQuery('#subpage1'), {
            data: 'lang=de&param1=foo&param2=bar',
            reloadPage: true,
            type: 'get'
        });
    }
    // go on loading #subpage2
});

jQuery(document).one('pageinit', '#subpage2', function() {
    // do something
});

【问题讨论】:

  • 你尝试过第一页的'pagebeforehide'事件吗?
  • 不是真的,因为当我转到 page.php#subpage2 时,#subpage1 从未显示。所以这没有意义。
  • 在页面加载事件中检查the documentation。甚至还有一个关于如何防止正常导航的示例。然后你就可以自己处理所有的页面加载了。
  • 请查看文档的第一行,说明“每当将外部页面加载到应用程序 DOM 中时”。它说external,而子页面似乎不是外部页面(请参阅stackoverflow.com/a/10182406/354436)。

标签: javascript jquery jquery-mobile


【解决方案1】:

您是否尝试过在 html 中将 body 样式设置为 display:none?然后如果页面加载正确,您可以设置它的显示属性吗?这应该是防止页面闪烁的“解决方法”?

【讨论】:

    猜你喜欢
    • 2021-05-06
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    相关资源
    最近更新 更多