0

I made an html page for my photos. When clicking on some area, a lightbox sort of feature appears. So basically a part of the page which is not visible up to then comes in the middle of the screen. I have a close button to get rid of it if someone wants, as well as the esc button.

However, and especially on phones, everyone clicks the phone back button. So I a trying to assign to the back button an event, that instead of "go back to the previous page" just "get rid of the lightbox".

Is that possible?

Many thanks, Elias

inasiopo
  • 55
  • 1
  • 10
  • [Similar question](http://stackoverflow.com/questions/464405/jquery-lightbox-with-proper-back-button-support), another [similar question](http://stackoverflow.com/questions/28063294/i-want-my-tablets-hardware-back-button-android-to-close-my-websites-lightbox), both using jQuery. And while the answer actually is 'no', [this article](http://www.webdesignerdepot.com/2013/03/how-to-manage-the-back-button-with-javascript/) describes a nice solution/workaround. – GolezTrol Oct 15 '15 at 17:20

1 Answers1

0

A bit clumsy but...

window.onbeforeunload = function() { 
    if (LiteBoxOpen) {
        var r = confirm("Do you wish to leave the page? Press no to just close image");
        if (r == true) {
            return true;
        } 
        closeLiteBox(); // what ever is the function to close your litebox
        return false;
     }
} };

Since you don't want to delete the users history, most users hate that. But you could.

Baine Sumpin
  • 142
  • 5