Question about keyboard key detection, need help

A

alkalsa

Happy 2007 all... :)

I am looking for a way in JavaScript in IE 7.0 only, to have it detect
the Backspace key on the keyboard.

So like,

<script>

if backSpaceKeyPressed {

do stuff....

}

</script>

I can't seem to get this to work. Can someone please help me?

AnGie%
 
B

Bart Van der Donck

I am looking for a way in JavaScript in IE 7.0 only, to have it detect
the Backspace key on the keyboard.
So like,
<script>
if backSpaceKeyPressed {
do stuff....
}
</script>

I can't seem to get this to work. Can someone please help me?

msdn.microsoft.com/workshop/author/dhtml/reference/events/onkeypress.asp
msdn.microsoft.com/workshop/author/dhtml/reference/objects/body.asp

<body onkeypress="if (event.keyCode==8) { alert('you pressed
backspace'); return false; }" onload="self.focus()">

Three remarks:

- focus needs to be in browser page (that's why I added the
onLoad-event)
- 'return false' is to prevent 'Go to previous page' (history back)
- MSIE proprietary

Hope this helps,
 
L

-Lost

Bart Van der Donck said:
msdn.microsoft.com/workshop/author/dhtml/reference/events/onkeypress.asp
msdn.microsoft.com/workshop/author/dhtml/reference/objects/body.asp

<body onkeypress="if (event.keyCode==8) { alert('you pressed
backspace'); return false; }" onload="self.focus()">

Three remarks:

- focus needs to be in browser page (that's why I added the
onLoad-event)
- 'return false' is to prevent 'Go to previous page' (history back)
- MSIE proprietary

No it is not. However, only onkeydown and onkeyup is reliable as the keyCode is always
set in those events.

-Lost
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,829
Messages
2,569,737
Members
45,525
Latest member
RosalindSa

Latest Threads

Top