<embed> vs. <object>
Which is the right/best tag to use in my HTML file when I want to display the Adobe PDF viewer?
Right now I'm using the code below, but there are weird side effects (e.g. it seems to steal the starting focus that I've set to another <input>
text box; it doesn't seem to play real well with the jQueryUI Resizeable class; etc.)
<embed src="abc.pdf" type="application/pdf" />
Could I even do the same thing with the <object>
tag? Are there advantages/disadvantages to using one tag vs. the other?
Solution 1:
OBJECT vs. EMBED - why not always use embed?
Bottom line: OBJECT is Good, EMBED is Old. Beside's IE's PARAM tags, any content between OBJECT tags will get rendered if the browser doesn't support OBJECT's referred plugin, and apparently, the content gets http requested regardless if it gets rendered or not.
object
is the current standard tag to embed something on a page. embed
was included by Netscape (along img
) before anything like object
were on the w3c mind.
This is how you include a PDF with object
:
<object data="data/test.pdf" type="application/pdf" width="300" height="200">
alt : <a href="data/test.pdf">test.pdf</a>
</object>
If you really need the inline PDF to show in almost every browser, as older browsers understand embed
but not object
, you'll need to do this:
<object data="abc.pdf" type="application/pdf">
<embed src="abc.pdf" type="application/pdf" />
</object>
This version does not validate.
Solution 2:
Answer updated for 2020:
Both <object>
and <embed>
are included in the WHAT-WG HTML Living Standard (Sept 2020).
<object>
The object element can represent an external resource, which,
depending on the type of the resource, will either be treated as an
image, as a child browsing context, or as an external resource to be
processed by a plugin.
<embed>
The embed element provides an integration point for an external (typically non-HTML) application or interactive content.
Are there advantages/disadvantages to using one tag vs. the other?
The object element can represent an external resource, which, depending on the type of the resource, will either be treated as an image, as a child browsing context, or as an external resource to be processed by a plugin.
<embed>
The embed element provides an integration point for an external (typically non-HTML) application or interactive content.
Are there advantages/disadvantages to using one tag vs. the other?
The opinion of Mozilla Developer Network (MDN) appears (albeit fairly subtly) to very marginally favour <object>
over <embed>
but, overwhelmingly, MDN wants to recommend that wherever you can, you avoid embedding external content entirely.
[...] you are unlikely to use these elements very much — Applets haven't been used for years, Flash is no longer very popular, due to a number of reasons (see The case against plugins, below), PDFs tend to be better linked to than embedded, and other content such as images and video have much better, easier elements to handle those. Plugins and these embedding methods are really a legacy technology, and we are mainly mentioning them in case you come across them in certain circumstances like intranets, or enterprise projects.
Once upon a time, plugins were indispensable on the Web. Remember the days when you had to install Adobe Flash Player just to watch a movie online? And then you constantly got annoying alerts about updating Flash Player and your Java Runtime Environment. Web technologies have since grown much more robust, and those days are over. For virtually all applications, it's time to stop delivering content that depends on plugins and start taking advantage of Web technologies instead.
Source: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#The_%3Cembed%3E_and_%3Cobject%3E_elements
Solution 3:
Some other options:
<object type="application/pdf" data="filename.pdf" width="100%" height="100%">
</object>
<object type="application/pdf" data="#request.localhost#_includes/filename.pdf"
width="100%" height="100%">
<param name="src" value="#request.localhost#_includes/filename.pdf">
</object>