Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Event handlers Date: Mon, 02 Jan 2017 02:35:59 +0100 Organization: PointedEars Software (PES) Lines: 70 Message-ID: <1770042.oMNUckLgyt@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1483320961 1374 eJwFwQkRADAIAzBLPAUOOd0Y/iUsCU/NW8hIxMbaoZaBxTaTJ5CL9uFkvxvtvn1YM7YiqsQHFCgQ6A== (2 Jan 2017 01:36:01 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 2 Jan 2017 01:36:01 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Lock: sha1:p+xGyRXyEo+82bWMyeTcVM89240= X-NNTP-Posting-Host: eJwFwQkBACAIA8BKCA40juPpH8E7mC/P2A7fGEw3X5zqs65eGhduPMqmUBAAtKayxOuZJvgBKJcRhQ== Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. 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: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.