Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 266775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:28:19+00:00 2026-05-11T23:28:19+00:00

I’ve been trying to handle the onkeydown event across multiple frames (no, I unfortunately

  • 0

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 question here). I’m getting a handle on the document in the other frame, and setting it’s onkeydown handler equal to my function. No error is thrown, but when I later check the document’s settings, onkeydown is null. I’ve gotten the same results in IE6 and IE7. What am I doing wrong?

  • Function

     function setKeyHook(doc)
     {
         try{               
             if (doc)
                 if (parent.TOP.handleKeypress){
                     doc.onkeydown = parent.TOP.handleKeypress;
                     logMessage('Attached handler');
                 }
                 else{
                     logMessage('No handleKeypress');
                 }
             else
                 logMessage('No doc');
         }
         catch (ex){
             logMessage(ex.toString());
         }
     }
    
  • Call

setTimeout("setKeyHook(parent.document.getElementById(\"bottom\").document);", 1000);
  • Output
   Attached handler
  • After execution
    BOTTOM.protocol = HyperText Transfer Protocol
    BOTTOM.onkeypress = null
    BOTTOM.onrowenter = null
    BOTTOM.onmousedown = null

How should I apply the same event handler across frames?

Note: This needs to work (and only work) in IE6 and IE7.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:28:20+00:00Added an answer on May 11, 2026 at 11:28 pm

    I got this to work

    frameset.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
       "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
        <title>Test</title>
    </head>
    <frameset rows="50%,50%">
        <frame src="frame1.html" name="TOP">
        <frame src="frame2.html" name="BOTTOM">
    </frameset>
    </html>
    

    frame1.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
       "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
        <title>Frame 1</title>
        <script type="text/javascript">
        onload = function()
        {
            top.frames.BOTTOM.document.onkeydown = 
            self.document.onkeydown = function( evt )
            {
                return function()
                {
                    // Just an example to show it's working
                    document.getElementById( 'output' ).value += String.fromCharCode( evt.keyCode );
                }
            }( window.event );
        }
    
        </script>
    </head>
    <body>
        frame1
        <textarea id="output"></textarea>  
    </body>
    </html>
    

    frame2.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
       "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
        <title>Frame 2</title>
    </head>
    <body>
        frame2
        <textarea></textarea>
    </body>
    </html>
    

    First of all, it always pays to be fairly explicit with your object references. Using proprietary DOM shortcuts (such as window.frameName) just add unnecessary error potential. This is why my script explicitly looks in the frames collection of the window object.

    Next is to familiarize yourself with the various built-in window references in the DOM when dealing with framesets. There are 4 total

    1. window – The current window. This is also implied when left out (i.e., window.onload === onload)
    2. parent – The parent window to the current
    3. top – The topmost window in a frameset family. parent === top when you have only one frameset.
    4. self – alias of window

    So basically what I’ve done here is, when the onload event fires in the frame1 window, is add a handler function to the keydown event for the documents in both of the frame windows.

    That function uses a closure to ensure that the event generated in frame1 is available to the actual handler, regardless of which window generated the keydown event. This is necessary because of how IE does events. Whereas other browser create new event objects as they occur and passes them to event hanlders, IE just modifies the global event object (referenced via window.event or more simple, just event) to reflect the current event.

    I hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.