...

View Full Version : key stroke capture NS7



Kor
03-19-2004, 08:39 AM
Any ideea why this script does not work in NS7... Looks OK to me...



<html>
<head>
<script>
function NNKeyCap(thisOne) {
if (thisOne.which == 13)
{alert('That\'s the ENTER key')};
}

function IEKeyCap()
{
if (window.event.keyCode == 13)
{alert('That\'s the ENTER key')};
}

if (navigator.appName == 'Netscape')
{window.captureEvents(Event.KEYPRESS);window.onKeyPress = NNKeyCap;}
else{window.onKeyPress = IEKeyCap;}
//-->
</script>
</head>
<body>
</body>
</html>

Kor
03-19-2004, 08:40 AM
this forum ignore my back slash. ok, look at:

Any ideea why this script does not work in NS7... Looks OK to me...



<html>
<head>
<script>
function NNKeyCap(thisOne) {
if (thisOne.which == 13)
{alert('That is the ENTER key')};
}

function IEKeyCap()
{
if (window.event.keyCode == 13)
{alert('That is the ENTER key')};
}

if (navigator.appName == 'Netscape')
{window.captureEvents(Event.KEYPRESS);window.onKeyPress = NNKeyCap;}
else{window.onKeyPress = IEKeyCap;}
//-->
</script>
</head>
<body>
</body>
</html>

glenngv
03-19-2004, 09:19 AM
event handlers should be lowercase.
But I think the captureEvents technique is for NS4 only.
You can now directly assign the window event handlers in NS6+ just like in IE

window.onkeypress = function(e){
var k = (e) ? e.which:event.keyCode;
if (k==13) alert("That is ENTER key.")
}

Kor
03-19-2004, 02:35 PM
Thanks, this works for NS7, but not for IE6...:)

I suppose IE6 don't support window.onkeyup as an event handler

glenngv
03-22-2004, 06:52 AM
Try this:

document.onkeyup = function(e){
var k = (e) ? e.which:event.keyCode;
alert(k);
}

Kor
03-22-2004, 07:25 AM
yea, that should work, thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum