SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Browser onkeydown event compatability.

    Hi all,

    I am working on a rather large JS project and have run into a bit of a problem. I need to capture a key event and have this key capture work on all (semi-modern) browsers.

    What I am using now.

    document.onkeydown = containerKeyEvent;

    .
    .
    .
    function containerKeyEvent(evt){
    //i imagine I need to choose between evt.keyCode and evt.which
    //if(document.all) this is explorer....etc
    //various key event capture code

    }

    Now, my problem is, this code works on most browsers, but not on Netscape 7.0 on Mac. It does work on Netscape 7.1 on Red Hat Linux, IE 6 Windows, Firefox ?, Konqueror, safari,.....

    So, what do I need to make this work in Netscape 7.0 on mac? Do I need to use onkeypress instead? I do not have a large amount of time to experiment with this, and I do not have ready access to Netscape 7.0, which is making this difficult. Thanks in advance
    AFrieze

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onkeydown has weird issues. Instead of that, try onkeyup instead. Remeber, in the world of keyboards, what goes down must come up

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response chris_fuil.
    The only problem with onkeyup is the matter of how intuitive it is. The main key events I am capturing are arrow keys which move a text box around(Its a spreadsheet). Is there anyway to test if the browser supports onkeydown? If there is I could easily switch between the two methods.
    Andrew

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All modern browsers support onkeyup and onkeydown...

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria
    All modern browsers support onkeyup and onkeydown...
    So one would think...Yet it does not seem to work on netscape 7 on mac. This could just be that is doesn't like the keyevent put on document? Or am I doing something wrong?


  6. #6
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've actually heard that's not just on mac, but Netscape 7 in general. This is why I like to use onkeyup, as I hear weird things about onkeypress/onkeydown/whatever issue.

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all

    I am rapidly finding out that I do not have the resources to test my program on a large number of browsers/OS. Would it be ok to start a new thread with a link to a demo and ask people what they think and what errors they run into?

    AFrieze


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •