-1

I am using

$(document).keydown(function (event) {
  alert(event.keyCode);
});

This function works great when the page is loaded..Now when i click on any part of the page and then when i press any key this event is not firing and alert does not come..

Why?

Ravi Tuvar
  • 191
  • 1
  • 2
  • 14

1 Answers1

2

jsfiddle.net/5cyqC/3 click here and then click on Server Error oe anywhere else... and then see

You are setting the focus to the content of an iframe.

This is a separate document and events do not bubble out of it into the parent document.

If you want to capture events from it, you will need to bind the event handlers to the document loaded in the frame.

The Same Origin Policy will apply.

See this question for questions about communicating across iframes when the same origin policy blocks normal communication.

Note that there is no way to work around it from only one side as this would be a major security flaw. (For example, someone could put a banking website in a frame and then listen for keypress events in the bank's form to steal passwords.)

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335