-
Notifications
You must be signed in to change notification settings - Fork 264
Unload: update outdated example #639
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
Conversation
97c6513
to
3f0ff89
Compare
I'd also add a note that in Firefox (and maybe in some other places?) a message is ignored. |
I thought about it, but are jQuery API docs the right place to teach people JavaScript? This isn't a jQuery specific behaviour. |
We're already making this event special by setting What do you think, @dmethvin? |
@@ -28,7 +28,7 @@ | |||
<p>Any <code>unload</code> event handler should be bound to the <code>window</code> object:</p> | |||
<pre><code> | |||
$( window ).unload(function() { | |||
alert( "Handler for .unload() called." ); | |||
return "Handler for .unload() called."; | |||
}); | |||
</code></pre> | |||
<p>After this code executes, the alert will be displayed whenever the browser leaves the current page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/alert/message/ maybe?
s/will be/may be/ as well?
I believe we've gotten bug reports about this in the past, so perhaps we can add something to the warning already there. |
Just for the reference, dropping in jquery/learn.jquery.com#608 too. Might be worth it to mention it there. |
Added a sentence warning about it. I don't think we should go in-depth. @dmethvin What do you think? |
}); | ||
</code></pre> | ||
<p>After this code executes, the alert will be displayed whenever the browser leaves the current page. | ||
It is not possible to cancel the <code>unload</code> event with <code>.preventDefault()</code>. This event is available so that scripts can perform cleanup when the user leaves the page. | ||
<p>Most browsers will ignore calls to <code>alert()</code>, <code>confirm()</code> and <code>prompt()</code> inside the event handler. Depending on the browser, the message you return will be used in a confirmation dialog. It is not possible to cancel the <code>unload</code> event with <code>.preventDefault()</code>. This event is available so that scripts can perform cleanup when the user leaves the page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tab? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops! Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mzgol Does the rest LGTY?
6c3d7a0
to
7240ac0
Compare
What about the info that some browsers will ignore the message at all? |
I agree the comments here should be kept simple and not go too deep. It's always a bit frustrating when an API reference turns into a big "how to write JavaScript in the browser" article. Fortunately this page is pretty short at this point so we're not adding that much more to read.
This is a great point, maybe move this to the beginning in its own paragraph? That brings up the async operation trap, so perhaps add a sentence after it like, "Note that the browser may cancel or deny asynchronous operations attempted in this handler, such as AJAX or setTimeout."
Maybe something like this instead? "The string you return may be used in a browser confirmation dialog, but not all browsers support this." The warning already covers this ground again so I don't think we need much more. |
@dmethvin That sounds good. :) Michał Gołębiowski |
7240ac0
to
df4240a
Compare
df4240a
to
b44ca0a
Compare
LGTM! |
Would fix #388.