Gossamer Forum
Home : General : Perl Programming :

JS window.event

Quote Reply
JS window.event
Does anyone know why the following works in IE but not NS ?

Code:
function check_key() {
alert(window.event.keyCode);
if (window.event.keyCode == 13) {
return false;
}
}

Im using:

<body onkeypress="return check_key();">

Last edited by:

Paul: Apr 1, 2002, 3:04 AM
Quote Reply
Re: [Paul] JS window.event In reply to
Hmm one day I'll stop answering my own questions :)

>>
Internet Explorer and Netscape have different implementations for the KeyPress event. One difference is in how to retrieve the character that was pressed. IE uses event.keyCode and Netscape uses event.which. Also, Netscape only recognizes the event object if it is passed in from the text field's event handler. IE can use the passed-in event or can reference window.event without it being passed in.
<<
Quote Reply
Re: [Paul] JS window.event In reply to
Hmm still doesn't seem to work though.

With IE if I do:

Code:
if (window.event.keyCode == 13) {
return false;
}

....it works fine, but with NS if I do:

Code:
if (mykey == 13) {
return false;
}

....it doesnt work and the frame with the JS code in reloads to the wrong page when it shouldn't reload at all.

If I do alert(mykey) it shows 13 which is right :(
Quote Reply
Re: [Paul] JS window.event In reply to
Have you ever considered a Javascript book? :-)

- wil
Quote Reply
Re: [Paul] JS window.event In reply to
<script language="JavaScript1.2"><!--
function netscapeKeyPress(e) {
if (e.which == 13)
return false;
}

function microsoftKeyPress() {
if (window.event.keyCode == 13)
return false;
}

if (navigator.appName == 'Netscape') {
window.captureEvents(Event.KEYPRESS);
window.onKeyPress = netscapeKeyPress;
}
//--></script>

<body onKeyPress="microsoftKeyPress()">

Bob
http://totallyfreeads.com
Quote Reply
Re: [lanerj] JS window.event In reply to
thanks.

thats pretty similar to what i have but even when i return false the frame reloads :( with ie it doesnt

you can see what i mean here:

http://213.106.15.150/...bin/chat2/wochat.cgi

gossamer/gossamer

Last edited by:

Paul: Apr 1, 2002, 6:31 AM
Quote Reply
Re: [lanerj] JS window.event In reply to
I noticed someone logged into the chat room ...not sure who it was, anyway it was spewing errors whilst I was editing something but it is working now.
Quote Reply
Re: [Paul] JS window.event In reply to
Yep that was me. Didn't have time had to go.
Just tried then and got a js error with netscape -

JavaScript Error:
http://213.106.15.150/cgi-bin/chat2/wochat.cgi?do=load_frames&frame=frameset_bottom&sessionid=OJ70q0NkaN9ij1J297GxJAgdbsDHYiV3gflj9C8T6PBb1AtnhE&Username=me&Room_Name=Default,
line 125:

send is not defined.
JavaScript Error:
http://213.106.15.150/cgi-bin/chat2/wochat.cgi?do=load_frames&frame=frameset_bottom&sessionid=OJ70q0NkaN9ij1J297GxJAgdbsDHYiV3gflj9C8T6PBb1AtnhE&Username=me&Room_Name=Default,
line 91:

send is not defined.
JavaScript Error:
http://213.106.15.150/cgi-bin/chat2/wochat.cgi?do=load_frames&frame=frameset_bottom&sessionid=OJ70q0NkaN9ij1J297GxJAgdbsDHYiV3gflj9C8T6PBb1AtnhE&Username=me&Room_Name=Default,
line 35:

send is not defined.
JavaScript Error:
http://213.106.15.150/cgi-bin/chat2/wochat.cgi?do=load_frames&frame=frameset_right&sessionid=jGIk90kVjio1o3GgvAghsYcXqxAKjIN8W39mSFP0KS84C5tj45&Room_Name=Default,
line 40:

rooms is not defined.

Bob
http://totallyfreeads.com
Quote Reply
Re: [lanerj] JS window.event In reply to
Oh thanks...that might be whats wrong with NS then. I don't get any errors with 6.2...or at least I don't see any alerts.

I'll fix those up (although Im not sure whats causing them as IE doesn't give errors)...guess there is a difference in how NS interprets the code....
Quote Reply
Re: [lanerj] JS window.event In reply to
I don't understand those errors.

rooms and send are both defined as form names.

Unsure

Last edited by:

Paul: Apr 2, 2002, 2:36 AM
Quote Reply
Re: [Paul] JS window.event In reply to
Ok I renamed it to sender and it cleared up those errors but now I'm getting:

JavaScript Error:

line 35:

top.low.sender has no properties.

....if there are any JS experts reading please help :(

Last edited by:

Paul: Apr 2, 2002, 2:55 AM
Quote Reply
Re: [Paul] JS window.event In reply to
Mmmm perhaps?

http://developer.irt.org/script/324.htm

After serching the net it appears to be a netscape bug.

Last edited by:

Paul: Apr 2, 2002, 3:11 AM
Quote Reply
Re: [lanerj] JS window.event In reply to
Woohooo....persistance paid off :)

I got my thinking cap on and managed to solve it. Seems to be working now in Netscape and IE.

I just have one weird error left:

Error: redeclaration of const kIOServiceProgID
Source File: chrome://communicator/content/utilityOverlay.js
Line: 1

However it doesnt seem to affect anything.

Last edited by:

Paul: Apr 2, 2002, 4:17 AM
Quote Reply
Re: [Paul] JS window.event In reply to
Paul I now get this with mie in your top left frame after log in-
An error occured processing your request:

Can't use an undefined value as a HASH reference at admin/Library/Chat/Handle.pm line 229.

Caller: Chat::Handle, admin/Library/Chat/Handle.pm, 229

and this is the js error from netscape -
JavaScript Error:
http://213.106.15.150/cgi-bin/chat2/wochat.cgi?do=load_frames&frame=frameset_right&sessionid=SHs2kViksjSjlhfTBMJBbOol8KETFlIy1aU4jQ7faSd4KsmTYw&Room_Name=Default,
line 40:

top.high.right.rooms has no properties.

may I suggest trying a js forum. There is an excellent one at http://forums.internet.com/ the guys there realy know there stuff.

Bob
http://totallyfreeads.com
Quote Reply
Re: [lanerj] JS window.event In reply to
HI,

If you log out and back in it should fix that perl error (I'll fix it though). Thanks for the link too.

I just don't get NS's problem. I have two frames:

high and low

Within high I have left and right.

In IE to reference something in another frame (say high+left) I can just do:

top.high.left.form_name.form_field.value

....with NS it just tells me top.high.left has no properties....grrrrr

Last edited by:

Paul: Apr 2, 2002, 4:39 AM
Quote Reply
Re: [lanerj] JS window.event In reply to
update-
mie is saying you have a page error -

Line: 35
Char: 4
Error: 'top.low.sender.Message' is not an object
Code: 0

Bob
http:totallyfreeads.com
Quote Reply
Re: [lanerj] JS window.event In reply to
Hmm where did you get that error?

It should be post.Message not sender.Message which is causing the error but I can't find it.
Quote Reply
Re: [Paul] JS window.event In reply to
well I don't get that error any more.

Bob
http://totallyfreeads.com
Quote Reply
Re: [lanerj] JS window.event In reply to
Ooooo Im gonna nail this sucker if it kills me :)

I think Im closer. I needed:

top.low.document.post.Username.value

instead of:

top.low.post.Username.value
Quote Reply
Re: [lanerj] JS window.event In reply to
Hmm went out for a few holes of golf but didn't exactly come back refreshed..ah well :)

Almost everything is fixed now apart from the fact that with NS the bottom frame reloads if you try to submit your message by hitting return...grrr.

Using event.which and returning false doesn't seem to stop it. I've tried adding return false; in 100 different places and nothing works with NS....IE not a problem Pirate