In my JSP web application I am using the embed
element to display a PDF.
<embed src="someurl" width="900">
The someurl
will return a PDF stream in one case and a text stream in another case:
if (IamPDF) {
response.setContentType("application/pdf");
/* rest of stream flushing */
} else {
response.setContentType("text/html");
/* rest of stream flushing */
}
I can flush the PDF stream without problem in both IE and Chrome. In case of a text stream, IE is unable to display the stream, but it’s working in Chrome. And I did not specify any type in the embed
element. How to make it work in IE?
Although supported by the browsers, the <embed> is a deprecated HTML tag and is not part of the HTML4 standard.
Embedded elements are objects and controls that can be embedded on a page, form, subform, or document. Elements that can be embedded include: Views. Folders. Outlines.
The <embed> tag defines a container for an external resource, such as a web page, a picture, a media player, or a plug-in application.
The <embed> HTML element embeds external content at the specified point in the document. This content is provided by an external application or other source of interactive content such as a browser plug-in.
You can resolve this by setting the type
attribute of the embed
element.
For HTML
<embed src="someurl" type="text/html" width="900">
and for PDF
<embed src="someurl" type="application/pdf" width="900">
Quoting the embed
element specification:
The
type
attribute, if present, gives the MIME type by which the plugin to instantiate is selected. The value must be a valid MIME type. If both thetype
attribute and thesrc
attribute are present, then thetype
attribute must specify the same type as the explicit Content-Type metadata of the resource given by thesrc
attribute.
Links to MIME type and valid MIME type removed, they’re irrelevant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With