Click to See Complete Forum and Search --> : i have a possibly very stupid problem


serAph1m
09-18-2003, 11:04 AM
code:


...
<link rel="stylesheet" href="/jboxx-manager/menu.css" type="text/css">
</head>

<script language="JavaScript">
<!--
document.oncontextmenu=new Function("return false;");
window.focus();

function Close_KeyDownHandler()
{
keypress = event.keyCode;
if (keypress == 27)
{
top.window.close();
}
}
-->
</script>

<body style="margin: 0px 0px 0px 0px;" bgcolor="#FFFFFF" onkeydown="Close_KeyDownHandler();">
...



this throws the following error:

Error: event is not defined
Source File: http://localhost:8080/jboxx-manager/help/description.jsp




I know its probably something simple - but whats frustrating is that this code works in IE!

sciguyryan
09-18-2003, 11:07 AM
ummm page can not be displayed?!

serAph1m
09-18-2003, 11:13 AM
hehe localhost calls your own computer :) thats why. Im developing the interface for a J2EE webapp and running it on a local app server for testing purposes.


anyway, ive been searching like mad about mozilla and event handling... but nothing yet.

requestcode
09-18-2003, 11:43 AM
This works. I used ASCII 100 (lower case d). It also works in NS7.
<html>
<head>
<title>Test</title>
<script language="JavaScript">
<!--
document.oncontextmenu=new Function("return false");
window.focus();
IE5=document.all? 1:0
function Close_KeyDownHandler(e)
{
keypress = !IE5? e.which:event.keyCode;
if (keypress == 100)
{
window.close();
}
}
-->
</script>
</head>
<body onKeyPress="Close_KeyDownHandler(event);">
</body>
</html>

pyro
09-18-2003, 12:07 PM
Yes, In Gecko browsers, you need to pass the event handler, whereas in IE, you can just use it...

serAph1m
09-18-2003, 12:14 PM
ok I used the code (thanks a TON!!) and its error free

however, I cant get it to actually work! :)

I changed the ascii value from 100 to 27 and it still doesnt close the windows - IE or Mozilla :(

btw: 27 is the code for the escape key is it not?

requestcode
09-18-2003, 02:15 PM
It works for me in IE, but in Netscape pressing the esc key returns zero. Also are you using onKeyPress or onKeyDown?

serAph1m
09-18-2003, 02:45 PM
Originally posted by requestcode
It works for me in IE, but in Netscape pressing the esc key returns zero. Also are you using onKeyPress or onKeyDown?

on key down... I'll try press