I have a website at domain A that contains an iframe used to show a video, which is hosted on YouTube. On the iframe load event, I am attempting to register for the keyup event in the iframe so I can close the video when a client presses the escape key. Here is an example of my code:
$(myIFrame).bind('load', function() {
$(myIFrame.contentWindow.document).keyup(function(event) {
console.log(event.keyCode);
});
alert('Event Registered');
});
I am getting the following exceptions:
Firefox: Error: Permission denied to access property "document"
Chrome: Uncaught SecurityError: Blocked a frame with origin "A" from accessing a frame with origin "https://www.youtube-nocookie.com". Protocols, domains, and ports must match.
Is there any way to register for events in a cross-origin iframe?