Skip to content

Commit c39c53d

Browse files
committed
Fix mistake in beforeunload description
And add an errata for it Closes marijnh#489
1 parent adf3481 commit c39c53d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

15_event.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -724,16 +724,16 @@ propagate.
724724

725725
{{index "beforeunload event", "page reload", "preventDefault method"}}
726726

727-
When a page is closed or navigated away from (for example, by following
728-
a link), a `"beforeunload"` event fires. The main use of this event is
729-
to prevent the user from accidentally losing work by closing a
730-
document. Preventing the page from unloading is not, as you might
731-
expect, done with the `preventDefault` method. Instead, it is done by
732-
returning a non-null value from the handler. When you do that, the
733-
browser will show the user a dialog asking if they are sure they want to
734-
leave the page. This mechanism ensures that a user is always able to
735-
leave, even on malicious pages that would prefer to keep them there
736-
forever and force them to look at dodgy weight-loss ads.
727+
When a page is closed or navigated away from (for example, by
728+
following a link), a `"beforeunload"` event fires. The main use of
729+
this event is to prevent the user from accidentally losing work by
730+
closing a document. If you prevent the default behavior on this event
731+
_and_ set the `returnValue` property on the event event object to a
732+
string, the browser will show the user a dialog asking if they really
733+
want to leave the page. That dialog might include your string, but
734+
because some malicious sites try to use these dialogs to confuse
735+
people into staying on their page to look at dodgy weight loss ads,
736+
most browsers no longer display them.
737737

738738
{{id timeline}}
739739

html/errata.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ <h2>Chapter 14</h2>
6363
<p><strong>Page 234</strong> (2nd) <em>Creating Nodes</em>: In the
6464
code, “edition” is misspelled as “editon”.</p>
6565

66+
<h2>Chapter 15</h2>
67+
68+
<p><strong>Page 258</strong> <em>Load Event</em>: The description of
69+
the <code>beforeunload</code> claims that you just need to return a
70+
string from your event handler. For handlers registered
71+
with <code>addEventListener</code> you, in fact, need to
72+
call <code>preventDefault</code> and set a <code>returnValue</code>
73+
property to get the warn-on-leave behavior.</p>
74+
6675
<h2>Chapter 16</h2>
6776

6877
<p><strong>Page 285</strong> (2nd) <em>Pausing the Game</em>: The text

0 commit comments

Comments
 (0)