Handle keyPress Accross Frames in IE

前端 未结 2 1108
醉梦人生
醉梦人生 2021-01-25 07:24

I\'ve been trying to handle the onkeydown event across multiple frames (no, I unfortunately cannot be rid of the frames) via javascript (see my previous questio

2条回答
  •  花落未央
    2021-01-25 07:34

    If you're having a problem reading the event object of a frame when the event is handled in another frame, you'll have to reference it explicitly

    var event = top.frames.BOTTOM.event;
    

    I've run into this issue myself, and the beginning of my event handler was

    var myFrame = top.frames[0];
    myFrame.onkeydown = keyboardHandler;
    
    function keyboardHandler(e) {
        if (!e && event) {
            e = event; //For handling the event in IE
        }
        if (!e && myFrame.contentWindow.event) {
            e = myFrame.contentWindow.event; //For handling event in IE6 from inside the iFrame
        }
    
        if (e) {
        ...
        }
    }
    

提交回复
热议问题