Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32045 > unrolled thread

Re: Event handlers

Started byThomas 'PointedEars' Lahn <PointedEars@web.de>
First post2017-01-02 02:35 +0100
Last post2017-01-02 02:35 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.javascript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Event handlers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-02 02:35 +0100

#32045 — Re: Event handlers

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-01-02 02:35 +0100
SubjectRe: Event handlers
Message-ID<1770042.oMNUckLgyt@PointedEars.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.

[toc] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web