【问题标题】:How to recover from an error loading page with jQuery mobile when safari components are hidden?隐藏 Safari 组件时如何使用 jQuery Mobile 从错误加载页面中恢复?
【发布时间】:2011-07-15 13:07:08
【问题描述】:

当您的移动网络应用程序添加到 iOS 主屏幕并且您选择使用此元标记隐藏 safari 组件时:

 <meta name="apple-mobile-web-app-capable" content="yes" />

如果您的某个页面加载错误,jQuery mobile 会显示错误消息覆盖并且当前页面上的所有链接都已失效。隐藏 Safari 组件后,无法轻松重新加载页面。您需要返回主屏幕并再次打开移动网络应用程序。在这种情况下,是否有更优雅的方式从错误中恢复?在移动 jQuery 中遇到页面加载错误后,有没有办法强制页面重新加载?

【问题讨论】:

    标签: jquery ios error-handling jquery-mobile iphone-standalone-web-app


    【解决方案1】:

    这是一个有趣的情况......

    如果我是你,我会尝试实现一个 .live() 事件绑定,当用户单击错误弹出窗口时,它会返回到功能状态。

    使用 firebug 找出弹出 div 有哪些区别类。

    【讨论】:

      【解决方案2】:

      发生错误事件时,调用window.location.reload(true) 将重新下载页面,因为第一个参数是true,而不是仅仅从缓存重新加载。

      如果您认为不需要请求页面,只需省略第一个参数。

      【讨论】:

        【解决方案3】:

        您可以处理事件 pageloadfailed 并恢复。以下是文档和示例代码:http://jquerymobile.com/test/docs/api/events.html

        $( document ).bind( "pageloadfailed", function( event, data ){
        
            // Let the framework know we're going to handle things.
        
            event.preventDefault();
        
            // ... attempt to load some other page ...
            // 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 );
        
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-10-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-12
          相关资源
          最近更新 更多