Problem capturing return key (keycode = 13) in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veronicab
    New Member
    • Mar 2006
    • 4

    Problem capturing return key (keycode = 13) in Firefox

    Hi,

    I have a small JavaScript code in a page to trap when user presses Return key.

    My problem is that if you visit the page and then enter a different url in address field, and press Return, that key press is also being captured. How can I distinguish when user is pressing Return on the address field in address bar?

    Works ok on IE, the problem appears only in Firefox.

    This is the code I have:

    Code:
    document.onkeyup = HandleKeyup;
     
    function HandleKeyup(e){
       if(!e){
         e = window.event;
     }
     if(e.keyCode == 13){
        SomeFunction();
     }
    }
    Thanks!
    Veronica
  • pshm
    New Member
    • Mar 2008
    • 20

    #2
    [code=html]
    document.onkeyu p = HandleKeyup;

    function HandleKeyup(e){
    if(!e){
    e = window.event;
    }
    if(e.which == 13){
    SomeFunction();
    }
    }
    [/code]

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      The address bar is not in the document, so I'm not sure how IE is capturing it, either.

      Comment

      Working...