Skip to content

Update error.xml #630

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

Closed
wants to merge 7 commits into from
Closed
Changes from 6 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
20 changes: 16 additions & 4 deletions entries/error.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,35 @@ $( "#book" )
})
.attr( "src", "missing.png" );
</code></pre>
<p>If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:</p>
<p>If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:</p>
<p>
<samp>Handler for .error() called.</samp>
</p>
<div class="warning">
<p>The event handler <em>must</em> be attached before the browser fires the error event, which is why the example sets the src attribute after attaching the handler. Also, the error event may not be correctly fired when the page is served locally; <code>error</code> relies on HTTP status codes and will generally not be triggered if the URL uses the <code>file:</code> protocol.</p>
<p>The event handler <em>must</em> be attached before the browser fires the <code>error</code> event, which is why the example sets the <code>src</code> attribute after attaching the handler. Also, the <code>error</code> event may not be correctly fired when the page is served locally; <code>error</code> relies on HTTP status codes and will generally not be triggered if the URL uses the <code>file:</code> protocol.</p>
</div>
<p>Note: A jQuery error event handler should not be attached to the window object. The browser fires the window's error event when a script error occurs. However, the window error event receives different arguments and has different return value requirements than conventional event handlers. Use <code>window.onerror</code> instead.</p>
<p>Note: A jQuery <code>error</code> event handler should not be attached to the <code>window</code> object. The browser fires the <code>window</code>'s <code>error</code> event when a script error occurs. However, the window <code>error</code> event receives different arguments and has different return value requirements than conventional event handlers. Use <code>window.onerror</code> instead.</p>
</longdesc>
<example>
<desc>To hide the "broken image" icons for IE users, you can try:</desc>
<desc>To hide the "broken image" icons for users of older versions of IE, you can write:</desc>
Copy link
Member

Choose a reason for hiding this comment

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

of older versions of IE

Which versions does that affect?

Copy link
Member Author

Choose a reason for hiding this comment

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

I remember is IE <= 10 but I can't find any reference. Someone with a hint on this?

Copy link
Member

Choose a reason for hiding this comment

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

No idea, honestly. I do think though that just saying "older versions of IE" means nothing so we should figure this out. Maybe @dmethvin or @timmywil have links to relevant discussions about this?

Copy link
Member

Choose a reason for hiding this comment

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

ping @AurelioDeRosa @dmethvin @timmywil is there anyone who knows this? If not I'll quickly test this out.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I mentioned elsewhere that I'm not sure when the "broken image" thing went away. Probably before IE9?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we specify IE9 for now and update in case of mistake?

<code><![CDATA[
// missing.png is an hypothetical missing image used to trigger the error event
$( "img" )
.error(function() {
$( this ).hide();
})
.attr( "src", "missing.png" );
]]></code>
</example>
<example>
<desc>To replace all the missing images with another, you can update the <code>src</code> attribute inside the callback passed to <code>.error()</code>. Be sure that the replacement image exists; otherwise the <code>error</code> event will be triggered indefinitely.</desc>
<code><![CDATA[
// If missing.png is missing, it is replaced by replacement.png
$( "img" )
.error(function() {
$( this ).attr( "src", "replacement.png" );
})
.attr( "src", "missing.png" );
]]></code>
</example>
<category slug="events/browser-events"/>
Expand Down