Closed thaxy closed 5 years ago
Thanks for spotting that. When you do window.onbeforeunload = () => "stop"
, that apparently still works, but when using addEventListener
, you do need to call preventDefault
and (on Chrome) set returnValue
. I've updated the text and added an errata entry in attached patch.
First of all thanks for this awesome book. I am not sure if I spotted a passage worth to update/review or if it is just me not understanding the content. But I am having problem to reproduce your described behavior.
3rd Edition, Page 255 Chapter 15: Handling Events Load Event
This doesn't work with the most recent versions of the Firefox and Chrome browser:
window.addEventListener('beforeunload', () => "non null return value");
While the following handler works and is contradicting because it calls the method
preventDefault
and returnsundefined
:You can find the same snippet of the code above in the official MDN docs.