Utilizing the Bootstrap modal to showcase details from my database, including text and image attachments. Upon clicking an image attachment, I focus a div
element to display a full-screen view of that image.
My goal is to allow the user to close the image div
by pressing the Esc
key only if it is currently visible on the screen (i.e., does not contain the "d-none" class). Although I successfully implemented this functionality using a keydown
event on the div
, I encountered an issue where the modal also closes automatically when pressing the Esc
key. How can I prevent this behavior?
I do not wish to permanently disable the "Closing on Esc key" feature of the modal; instead, I want to disable it specifically when the image div
is being displayed on the screen.
NOTE: If a script is required, please provide a solution using vanilla JavaScript.