Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch embed element type from PDF stream to text stream

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?

like image 505
Rookie007 Avatar asked Apr 08 '15 02:04

Rookie007


People also ask

Is embed tag Deprecated?

Although supported by the browsers, the <embed> is a deprecated HTML tag and is not part of the HTML4 standard.

What is an embedded element?

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.

What does embed tag do?

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.

What is embedded content HTML?

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.


1 Answers

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 the type attribute and the src attribute are present, then the type attribute must specify the same type as the explicit Content-Type metadata of the resource given by the src attribute.

Links to MIME type and valid MIME type removed, they’re irrelevant.

like image 110
user1709665 Avatar answered Sep 28 '22 11:09

user1709665