tuupola/lazyload

JavaScript not executed after clicking back button on IOS5

tuupola opened this issue · 4 comments

Not directly related to Lazy Load. On IOS5 mobile Safari JavaScript is not executed when user clicks back button. Thus when user navigates away from page and comes back using back button images which have not been loaded yet will not be loaded even after scrolling.

Dirty workaround is to call window.onpopstate handler twice. First call happens on initial pageload. It will bind the second call to make all images appear. Second call happens when user clicks back button.

window.onpopstate = function() { 
    window.onpopstate = function() {
        $("img.lazy").trigger("appear");
    };
};

This is not optimal but works until real solution can be found. Another option seems to be something like (untested code):

if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
    window.onpageshow = function(event) {
        if (event.persisted) {
            $("img.lazy").trigger("appear");
        };
    };
}

Has there come any other solution to this issue?

Looks like the issue is solved with iOS 6. Have tested the script on beta 4 and it's running as it should be without the solution about.

I probably need to sniff if user has iOS 5 and include the workaround. Thanks for the info!

Fixed in 1.8.2.