Fog Creek Software
Discussion Board




Javascript event bug with Firefox 1.0 on Win2k

Error: event is not defined
Source File: http://www.casadeamor.com/FogBUGZ/default.asp?command=new&pg=pgEditBug
Line: 1046

This error occurs whenever the edit page is loaded, and also whenever a key is pressed on that page, including when simply changing focus off the page using alt-tab. Seems to be a bug in the getKey() function:

function getKey(keyStroke)
{
    var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
    var keyString = String.fromCharCode(keyCode).toLowerCase();
    if (keyCode == 27) { return false; }
    return true;
}
if (document.layers) { document.captureEvents(Event.KEYPRESS); }
document.onkeydown = getKey;

...perhaps if you need to use browser-specific code, you might simply test for "event"?

    var keyCode = (event) ? event.keyCode : keyStroke.which;

Robert Brewer
Friday, November 26, 2004

*  Recent Topics

*  Fog Creek Home