Skip to content

Commit

Permalink
Ignore beforeunload event return value
Browse files Browse the repository at this point in the history
Instead of using it as the message to show to the user, simply compare
it against the empty string or not. This matches Gecko, WebKit, and
Blink (but not yet EdgeHTML).

Closes #952.
  • Loading branch information
domenic committed Apr 8, 2016
1 parent 374b54d commit 01d9870
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<li><dfn data-noexport="" data-x="dom-Node-appendChild" data-x-href="https://dom.spec.whatwg.org/#dom-node-appendchild"><code>appendChild()</code></dfn> method</li>
<li><dfn data-noexport="" data-x="dom-Node-cloneNode" data-x-href="https://dom.spec.whatwg.org/#dom-node-clonenode"><code>cloneNode()</code></dfn> method</li>
<li><dfn data-noexport="" data-x="dom-Document-importNode" data-x-href="https://dom.spec.whatwg.org/#dom-document-importnode"><code>importNode()</code></dfn> method</li>

<li><dfn data-noexport="" data-x="dom-Event-preventDefault" data-x-href="https://dom.spec.whatwg.org/#dom-event-preventdefault"><code>preventDefault()</code></dfn> method</li>
<li><dfn data-noexport="" data-x="dom-Element-id" data-x-href="https://dom.spec.whatwg.org/#dom-element-id"><code>id</code></dfn> attribute</li>
<li><dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#dom-node-textcontent"><code>textContent</code></dfn> attribute</li>

Expand Down Expand Up @@ -35736,10 +35736,11 @@ function playSound(id) {
sfx.oncanplaythrough = function () {
playSound('dog bark');
}
// meow when the user tries to leave
window.onbeforeunload = function () {
// meow when the user tries to leave,
// and have the browser ask them to stay
window.onbeforeunload = function (e) {
playSound('kitten mew');
return 'Are you sure you want to leave this awesome page?';
e.preventDefault();
}</pre>

</div>
Expand Down Expand Up @@ -82218,9 +82219,9 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
object is not the empty string, or if the event was canceled, then the user agent should ask the
user to confirm that they wish to unload the document.</p>

<p>The prompt shown by the user agent may include the string of the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute, <span
data-x="optionally truncate a simple dialog string">optionally truncated</span>.</p>
<p class="note">The message shown to the user is not customizable, but instead determined by
the user agent. In particular, the actual value of the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute is ignored.</p>

<p>The user agent must <span>pause</span> while waiting for the user's response.</p>

Expand Down Expand Up @@ -82395,29 +82396,28 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
attribute DOMString <span data-x="dom-BeforeUnloadEvent-returnValue">returnValue</span>;
};</pre>

<dl class="domintro">

<dt><var>event</var> . <code subdfn data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> [ = <var>value</var> ]</dt>

<dd>

<p>Returns the current return value of the event (the message to show the user).</p>

<p>Can be set, to update the message.</p>

</dd>

</dl>

<p class="note">There are no <code>BeforeUnloadEvent</code>-specific initialisation methods.</p>

<p>The <code>BeforeUnloadEvent</code> interface is a legacy interface which allows <span
data-x="prompt to unload a document">prompting to unload the document</span> to be controlled
not only by canceling the event, but by setting the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute to a value besides the
empty string. Authors should use the <code
data-x="dom-Event-preventDefault">preventDefault()</code> method, or other means of canceling
events, instead of using <code data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code>.</p>

<div w-nodev>

<p>The <dfn><code data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code></dfn> attribute
represents the message to show the user. When the event is created, the attribute must be set to
controls the process of <span data-x="prompt to unload a document">prompting to unload the
document</span>. When the event is created, the attribute must be set to
the empty string. On getting, it must return the last value it was set to. On setting, the
attribute must be set to the new value.</p>

<p class="note">This attribute is a <code data-x="">DOMString</code> only for historical reasons.
Any value besides the empty string will be treated as a request to ask the user for
confirmation.</p>

</div>


Expand Down Expand Up @@ -87048,7 +87048,7 @@ typedef <span>EventHandlerNonNull</span>? <dfn>EventHandler</dfn>;</pre>
<span w-nodev>as described above,</span> if the return value is false, the event is canceled
(except for <code data-x="event-mouseover">mouseover</code> events, where the return value has to
be true to cancel the event). With <code data-x="event-beforeunload">beforeunload</code> events,
the value is instead used to determine the message to show the user.</p>
the value is instead used to determine whether or not to prompt about unloading the document.</p>

<p>For historical reasons, the <code data-x="handler-onerror">onerror</code> handler has different
arguments:</p>
Expand Down

0 comments on commit 01d9870

Please sign in to comment.