Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32045
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Event handlers |
| Date | 2017-01-02 02:35 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1770042.oMNUckLgyt@PointedEars.de> (permalink) |
| References | <events-20170102012303@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> I have seen that in a Firefox from 2016 I can control
> events in event handlers
The proper term is event _listener_.
> with ».preventDefault()« and ».stopPropagation()«.
Those are not merely a feature in Firefox versions of 2016 but features of
the W3C DOM, implemented in several HTML user agents for more than 16 years
now. As you can read also in MDN.
You really need to lose your apparent beginner’s misconception that
everything related to ECMAScript or “JavaScript” is Netscape/Mozilla-
introduced, -related, or -only. Although MDN is undoubtedly the best
documentation available, there is much more out there on this than just
Mozilla; in fact, by now the biggest and most important part is *Google*
(considering the Chrome and Node.js market shares, both of which are based
on the V8 JavaScript script engine). You are doing a great misservice to
your students, if any, by continuing to ignore that fact (and not training
them in using the much superior Chrome DevTools instead; see the FAQ).
> But what about the return value of the event handler?
> Returning false does not seem to have the same effect
> as ».stopPropagation()«.
This is the proprietary way to say .preventDefault() for some events (for
others it is “true”), but only in event listeners added using event-handler
properties:
….on… = function (…) {
/* … */
return …;
};
> Can I safely omit the return statement from my event
> handler, or should I always return true (In the case
> of events like »click« or »contextmenu«)?
Depends.
> What would be a good way to write an event handler
_listener_
> targetting only 2017 browsers that
>
> 1.) does not stop further propagation
….addEventListener("…", function (event) {
/* Do not call event.stopPropagation() */
}, …);
> 2.) stops further propagation?
….addEventListener("…", function (event) {
/* … */
event.stopPropagation();
/* … */
}, …);
Next time, RTFM.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread
Re: Event handlers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-02 02:35 +0100
csiph-web