Skip to content

JavaScript not executed after clicking back button on IOS5 #30

Closed
tuupola opened this Issue Mar 8, 2012 · 4 comments

3 participants

@tuupola
Owner
tuupola commented Mar 8, 2012

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");
        };
    };
}
@tuupola tuupola was assigned Mar 8, 2012
@risto1913

Has there come any other solution to this issue?

@huangzj
huangzj commented Aug 24, 2012

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.

@tuupola
Owner
tuupola commented Aug 24, 2012

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

@tuupola
Owner
tuupola commented Nov 10, 2012

Fixed in 1.8.2.

@tuupola tuupola closed this Nov 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.