按“返回”按钮时未收到“pageshow” Safari上的按钮* IPad" [英] 'pageshow' is not received when pressing "back" button on Safari on *IPad"

查看:290
本文介绍了按“返回”按钮时未收到“pageshow” Safari上的按钮* IPad"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下处理程序:

        $(window).bind('pageshow', function() { alert("back to page"); });

当我离开页面时(按下链接)并返回页面(通过按返回按钮),不会调用 alert()(IPad 2,iOS 5.1)。

When I navigate away from the page (by pressing on a link) and return back to the page (by pressing the "back" button), the alert() is not called (IPad 2, iOS 5.1).

我做错了什么?我需要绑定的任何其他事件?

What am I doing wrong please? Any other event I need to bind to?

PS:有趣的是,当离开页面时, pagehide 被正确接收。

PS: interesting that pagehide is received properly when navigating away from the page.

推荐答案

您可以查看 pageshow <的持久属性/ code>事件。初始页面加载时设置为false。从缓存加载页面时,它设置为true。

You can check the persisted property of the pageshow event. It is set to false on initial page load. When page is loaded from cache it is set to true.

window.onpageshow = function(event) {
    if (event.persisted) {
        alert("back to page");
    }
};

由于某些原因,jQuery在事件中没有此属性。你可以从原始事件中找到它。

For some reason jQuery does not have this property in the event. You can find it from original event though.

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
      alert("back to page");
    }
};

这篇关于按“返回”按钮时未收到“pageshow” Safari上的按钮* IPad&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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