我的HTML页面上有一个 <iframe /> 元素,该框架与父页面位于同一个域中 .

鼠标事件正常在帧内发生,就像通常那样 .

但是,键盘事件根本不会触发,即使帧是聚焦的 .

如何在与父窗口在同一域上托管的 <iframe /> 内部触发键盘事件( onkeydownonkeyuponkeypress )?

Code I have tried (inside the iframe):

window.onKeyUp = function() {
    alert("This alert never pops up.");
}

window.onKeyDown = function() {
    alert("This alert never pops up either.");
}

window.onMouseUp = function() {
    alert("This alert pops up whenever I click the mouse over the iframe!");
}

window.onMouseDown = function() {
    alert("This alert also pops up whenever I click the mouse over the iframe!");
}