General developer forum

JS keyboard events problem on demo.moodle.net

 
Picture of Alex Ptroch
Re: JS keyboard events problem on demo.moodle.net
 

It turns out, there an iframe is used.

Here is the solution:


var win = false;
var par = false;
if (window) {
   if (window.frameElement) {
      if (window.parent && (window.parent != window)) {
         win = true;
         par = true;
      }
      else {
         win = true;
      }
   }
   else {
      win = true;
   }
}
if (win) {
   window.onkeypress = _this.keyPressW;
   window.onkeydown = _this.keyDownW;
   window.onkeyup = _this.keyUpW;
}
if (par) {
   window.parent.onkeypress = _this.keyPressW;
   window.parent.onkeydown = _this.keyDownW;      
   window.parent.onkeyup = _this.keyUpW;
}


Thank you. The topic is closed.

 
Average of ratings: -