Re: event handler in <body> doesn't work
- From: Chris <cmrchs@xxxxxxxxx>
- Date: Tue, 3 Nov 2009 03:05:58 -0800 (PST)
On Nov 3, 5:45 am, David Mark <dmark.cins...@xxxxxxxxx> wrote:
On Nov 2, 8:04 pm, JR <groups_j...@xxxxxxxxxxxx> wrote:
[snip]
It's really hard to say, but IE 8 (maybe 7 too?) works just fine with
document.onkeydown and event.returnValue = false, whereas FF3 and
others work well with document.onkeypress and e.preventDefault().
First off, keydown doesn't enter into this. As backspace is a
printable character, keypress is where you would expect to deal with
it. IIRC, this key (8) is an exception in IE (meaning you have to
deal with it in keyup).
So,
I've written code specifically for both cases, which can be put either
in a external .js file or at the bottom of the body tag (just before </
body>):
<script type="text/javascript">
document.onkeydown = function () { // IE
var e = window.event, keynum = e.keyCode;
if (keynum === 8) {
e.returnValue = false;
window.alert("Backspace pressed. keyCode = " +keynum);
}
};
document.onkeypress = function (evt) { // FF3, Safari, etc.
var keynum = evt.which;
if (keynum === 8) {
evt.preventDefault(); // Other W3C compliant browsers
window.alert("Backspace pressed. keyCode = " +keynum);
}
};
</script>
Start again. Use one listener function, attach to keypress and
keyup. First time through you can tell which to ignore. And if you
are going to use DOM0 (e.g. onkeypress), return false to prevent the
default action.
And ultimately, this is a horrible idea (breaking the back key).
as suggested, if I process the backspace-key for IE in keydown and for
FF in keypress it works well.
I don't want to break the standard, it's just that i try to understand
thank you all for your help!
Chris
.
- References:
- Re: event handler in <body> doesn't work
- From: JR
- Re: event handler in <body> doesn't work
- From: Chris
- Re: event handler in <body> doesn't work
- From: Chris
- Re: event handler in <body> doesn't work
- From: JR
- Re: event handler in <body> doesn't work
- From: Chris
- Re: event handler in <body> doesn't work
- From: JR
- Re: event handler in <body> doesn't work
- From: JR
- Re: event handler in <body> doesn't work
- From: David Mark
- Re: event handler in <body> doesn't work
- Prev by Date: Re: Detecting Internet Explorer 6
- Next by Date: Re: FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type? (2009-11-03)
- Previous by thread: Re: event handler in <body> doesn't work
- Next by thread: Re: event handler in <body> doesn't work
- Index(es):
Relevant Pages
|