The initial task is to handle hardware back button, when Fancybox image is in fullscreen mode. At now, when user press back button on phone, current page changes to previous and fulscreen image stays on foreground. The task is to close Fancybox image and stay at current page. I did it this way:
$(document).on("pagecontainerbeforechange", function (e, data) {
if (typeof data.toPage == "string" && data.options.direction == "back") {
if ($(".fancybox-is-open").length) {
// close fancybox
$.fancybox.close();
// stay at current page
data.toPage = '#' + $.mobile.activePage.data('url');
$.extend(data.options, {
changeHash: true
});
}
}
});
Fancybox is closed, user stays at current page, but when he clicks on Back button again, he gets on page, which is before previous one. How correctly prevent page change?