JS keyboard events problem on demo.moodle.net

JS keyboard events problem on demo.moodle.net

by Alex Ptroch -
Number of replies: 1

Hello!
I'm testing a small archive on the site demo.moodle.net
This is a SCORM package.
It contains Canvas HTML5 + JavaScript and lessons that require input from the keyboard.
I write on JS:
   
if (window) {
     window.onkeypress = _this.keyPressW;
     window.onkeydown = _this.keyDownW;
     window.onkeyup = _this.keyUpW;
}
if (document) {
     document.onkeypress = _this.keyPressD;
     document.onkeydown = _this.keyDownD;
     document.onkeyup = _this.keyUpD;
}
  
But no function works on demo.moodle.net  sad
  
Everything is working fine on my site.
    
Tell me please, is there a lock on demo.moodle.net for these events?
Why these events may not work?
   
Thank you so much in advance for your reply!
  
Average of ratings: -
In reply to Alex Ptroch

Re: JS keyboard events problem on demo.moodle.net

by Alex Ptroch -

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.