2015-10-15 74 views
0

我为我的照片做了一个html页面。 当点击某个区域时,会出现一个灯箱类功能。因此,基本上,到此为止不可见的页面的一部分出现在屏幕的中间。 我有一个关闭按钮来摆脱它,如果有人想要,以及esc按钮。返回按钮事件

但是,特别是在手机上,每个人都点击手机后退按钮。所以我试图给后退按钮分配一个事件,而不是“回到上一页”,只是“摆脱灯箱”。

这可能吗?

非常感谢, 埃利亚斯

+0

另一个[类似问题](http://stackoverflow.com/questions)(http://stackoverflow.com/questions/464405/jquery-lightbox-with-proper-back-button-support)/28063294/i-want-my-tablets-hardware-back-button-android-to-close-my-websites-lightbox),都使用jQuery。虽然答案实际上是'不',但[本文](http://www.webdesignerdepot.com/2013/03/how-to-manage-the-back-button-with-javascript/)描述了一个很好的解决方案/解决方法。 – GolezTrol

回答

0

有点笨拙,但...

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; 
    } 
} }; 

既然你不想删除用户历史,用户最讨厌这样。但你可以。