Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore beforeunload event return value #1001

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://html.spec.whatwg.org/#the-event-handler-processing-algorithm this would result in returnValue = "true" as far as I can tell. It seems better to return null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it'd be better to change this to e.preventDefault() IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's prolly a little clearer.

// 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