Reputation: 607
The following code renders a correct pdf in Chrome, when path-to.pdf
is a valid url pointing to a pdf. Other browsers (eg Firefox) render "alt text" when that path doesn't return a PDF, e.g. when data=""
. But Chrome will only render a white box where the PDF might have gone, and no alt text. Disabling Chrome's PDF viewer from chrome://plugins allows the alt text to be rendered, but alas now we can't see the PDFs.
<object type="application/pdf" data="path-to.pdf" >
<param name="view" value="fitH"/>
alt text.
</object>
This is what chrome displays, top box with data filled, and bottom without.
Is that even standards-compliant?
Upvotes: 2
Views: 1141
Reputation: 607
Ah, got it. Found the answer in sections 4.8.7.5-6 of the HTML 5.1 Specification (https://www.w3.org/html/wg/drafts/html/master/single-page.html#the-object-element):
If the data attribute is absent but the type attribute is present, and the user agent can find a plugin suitable according to the value of the type attribute, and either plugins aren't being sandboxed or the plugin can be secured, then that plugin should be used. If these conditions cannot be met, or if the plugin reports an error, jump to the step below labeled fallback. Otherwise abort these steps; once the plugin is completely loaded, queue a task to fire a simple event named load at the element.
Fallback: The object element represents the element's children, ignoring any leading param element children. This is the element's fallback content. If the element has an instantiated plugin, then unload it.
So I just checked if the data url wasn't defined before rendering, and if not, didn't give the <object>
either a data="url"
or a type="application/pdf"
attribute.
Upvotes: 3