An odd question this will be, but here goes. I have a page on which I show a photo in a large format, like a lightbox. When pressing ESC I close the page and return the user to the page where he came from, which shows the photos in a normal format:
$(document).keyup(function(e) {
if (e.keyCode == 27) {
var closeURL = $('.close').attr('href');
window.location = closeURL;
}
});
However, on the same lightbox page is also a side panel that may contain embedded Youtube videos. It is possible for users to enlarge that video to fullscreen by using the standard video controls of the Youtube player. If the user hits ESC in that scenario, it will close the fullscreen video and return to the lightbox page (standard embedded player behavior, which is what I want), however, the ESC key event then also triggers my keyup code which closes the Lightbox, undesirable in this specific scenario.
I've found this trickling down to be there in Chrome, but not in Firefox. Essentially what I want is for my ESC code to not be triggered when hitting ESC to close the Youtube player, yet for it to trigger only when users hit ESC as they watch the photo (and not the video).
I was looking into event.target to distinguish between these scenarios but no luck yet. Any ideas?
Update: I'm going to accept this Chrome-only bug for now. Still open to solutions though.
On computer keyboards, the Esc key Esc (named Escape key in the international standard series ISO/IEC 9995) is a key used to generate the escape character (which can be represented as ASCII code 27 in decimal, Unicode U+001B, or Ctrl + [ ).
import msvcrt import time aborted = False for time_remaining in range(10,0,-1): # First of all, check if ESCape was pressed if msvcrt. kbhit() and msvcrt. getch()==chr(27): aborted = True break print(str(time_remaining)) # so I can see loop is working time.
Short for Escape, Esc is a key found on the top-left corner of a computer keyboard. It allows the user to abort, cancel, or close an operation. For example, if a web page was loading slow on an Internet browser, pressing the Escape key stops the download.
I don't believe this is going to be possible. The Flash player captures input when it's focused - for example, if you click play in a YouTube video, then hit Ctrl-W to close the tab, it's not going to close until you click on the page outside of the video, returning focus to the browser.
Input control is effectively being passed to another process (the Flash player) while it's focused, so you're not going to be able to capture or act on input until the user explicitly returns control to the browser.
Maybe something like that would work :
$(document).not("iframe").keyup(...
Just stumbled on this.. I know this is a bit old but there is a possible solution (will require more work)...
You could wrap the youtube player in your own flash player (using the API or simply a container) and detect the keypress within flash. You could then call the same javascript function directly from your flash application so it doesn't matter whether you page or the flash app has focus the script you want to run will always be run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With