admin 管理员组文章数量: 1086019
I'm developing a custom "lightbox" photo gallery. I'm adding key event "listeners" (left>prev, right>next, esc>close), and I'm having the issue of Safari (or any fullscreen mode browser) exiting fullscreen mode on escape. My site works fine, just the viewer then has to resume fullscreen mode for Safari (and others).
Now, I know there's a way to bypass this. Facebook for instance, while looking at a photo in the "theatre" mode, can be closed with the esc key without causing my browser to exit fullscreen.
Any thoughts?
I'm developing a custom "lightbox" photo gallery. I'm adding key event "listeners" (left>prev, right>next, esc>close), and I'm having the issue of Safari (or any fullscreen mode browser) exiting fullscreen mode on escape. My site works fine, just the viewer then has to resume fullscreen mode for Safari (and others).
Now, I know there's a way to bypass this. Facebook for instance, while looking at a photo in the "theatre" mode, can be closed with the esc key without causing my browser to exit fullscreen.
Any thoughts?
Share Improve this question asked Jan 4, 2014 at 2:28 Joel HackneyJoel Hackney 1471 gold badge5 silver badges13 bronze badges 1- Does event.preventDefault() not work? – Henry Ing-Simmons Commented Jan 4, 2014 at 2:51
1 Answer
Reset to default 5Practically you cannot disable ESC key for browsers as that is a promise for user to at least have some control over their browser. However, you do have a way to bind an eventlistener to your element field (say your lightbox div) to catch the Event when Esc is pressed and suppress it, like below: (so when people press ESC over the gallery div it will not exit browser fullscreen)
document.querySelector("div.lightbox").addEventListener("keydown",function(e){
var charCode = e.charCode || e.keyCode || e.which;
if (charCode == 27){
alert("Escape is not suppressed for lightbox!");
return false;
}
});
Also many browsers toggle fullscreen mode with F11 key now.
本文标签: javascriptPrevent Esc Key from Exiting FullScreen App Mode on WebsiteStack Overflow
版权声明:本文标题:javascript - Prevent Esc Key from Exiting FullScreen App Mode on Website - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744019667a2519574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论