My onkeydown doenst work in a framed webpage

Posted on 2009-04-17
Last Modified: 2013-11-19
I have a window which will not recognise a onkeypressed event every time.
It seems maybe to be related to not having focus (in the right areas) or something when it opens.

My windows is filled with dynamic content in different frames & iframes.
I have now tried to put an alert() into all BODY-tags in all the (i)frames, in order to try find the problem.
But when the window opens the first time, its like NONE of the (i)frames are having focus or something, because NO alert-boxes pop up, before I explicit push left mouse key into one of the (i)frames and THEN press a key, e.g. [backspace] which is actually what I want to prevent from being possible in the whole window and (i)frames.
Question by:loopstudio
    LVL 19

    Expert Comment

    can you post the code

    Author Comment

    unfortunately NO..

    Im looking for somebody that either:
    - have experience with what to do with preventing [backspace] in IE in a webpage consisting of frames
    - have experiencing similar problems
    - knows about problems with focus being somewhere else than in one of the BODY-tags. Maybe someone know which object normally receives focus first or last
    - someone knows WHAT to do to allways ensure focus in the right place so that it can be catched by a "onkeydown"
    - maybe someone can provide an example code that allways works

    Additional info.. In some of the frames I have FLash-applets, in other I have Java-applets and in other again I have WMP-applet.
    My thought is that either the WINDOW itself or one of the applets is steeling the focus, so that my onkeydown on all the body-tags doesnt catch it!

    Author Comment

    Or maybe I should put my onkeydown recognition in a complete different place?

    Author Comment

    Maybe someone can tell me how to write a little code with an alertbox telling which element that receives focus?
    I want the alertbox to be fired no matter where it happens within the window.

    THAT could help me in order to find out what element is having the focus and therefore not firing the onkeydown event!

    Author Comment

    Maybe I should use an eventlistener?

    Have tried something like this:

       <title>DOM Event Example</title>

       <script type="text/javascript">

       // Function to add event listener to t
       function load() {
        var b_var = document.getElementById("b");
           b_var.addEventListener('focus', f(), false);

       function f() {
                return true



     <body onload="load();">
     <table id="t">
       <tr><td id="t1">one</td></tr>
       <tr><td id="t2">two</td></tr>
     <button id="b"></button>

    But it says that object doesnt support this property or method.

    Author Comment

    I can read that the ONKEYDOWN supports <BODY>, <OBJECT>, <TABLE> and more HTML tags and document, image, link and textarea are supported JavaScript objects.

    How can I write some code that catches onkeydown to all the above in a simple generic way?

    Accepted Solution

    I stop this issue. I have found out that its when using java-applets & Nobody is answering this thread.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now