On Wed, 05 Jan 2005 14:50:41 +0100, coolsti <coo (AT) nospam (DOT) com> wrote:
[snip]
When posting code to Usenet, please indent by two characters only (four at
the most). Newsreaders should wrap at less eighty characters and eight
character indents are likely to result in mangled formatting. Tabs are
also out of the question.
Quote:
function killReturn(evt) {
var mytarget;
var keyCode;
var is_ie;
if (document.all) { |
The document.all collection is not unique to Internet Explorer so you
cannot use it to infer the user agent currently in use. You don't need to
anyway: you're looking for support of specific features, so test for them.
function killReturn(evt) {evt = evt || event;
var target = evt.target || evt.srcElement,
keyCode = evt.keyCode || evt.which;
/* ... */
}
The logical OR (||) operator evaluates the first operand as a boolean. If
true, it returns the first operand itself. If false, the second operand it
returned regardless. It's a shorter way of writing
/* For a = b || c; */
if(b) {
a = b;
} else {
a = c;
}
or
a = b ? b : c;
[snip]
Quote:
if (!is_ie) {
evt.preventDefault();
evt.stopPropagation();
} |
Again, the proper test would be
if(evt.preventDefault && evt.stopPropagation) {
however I doubt stopPropagation is required here...
....and perhaps even returning false on its own will suffice.
[snip]
Quote:
} else {
alert("handler could not be attached");
} |
The third approach is to use the intrinsic event properties:
obj['on + evType] = fn;
[snip]
Hope that helps,
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.