Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<object> tag with pdf doesn't work in firefox and is messed up in IE

I have object tag that look like this :

<div id="embeddedPdfContainer"><object data="<c:url value="/download-pdf/${id }"/>" id="embeddedPdf"  width="820" height="1135" type="application/pdf"></object></div>

In chrome this tag works the way I want it to. In firefox it doesn't work at all and it's messed up in IE. Here's album with screenshots in each browser. What are my options here ?

Also on firefox I figured out that this pdf doesn't work with default firefoxe's pdf viewer. When I choose to use adobe acrobat extenstion for pdf documents it works perfectly.

like image 394
Marijus Avatar asked Mar 20 '14 13:03

Marijus


People also ask

Why are all of my .pdf now Firefox HTML?

If you right click on the PDF file that's saved on your computer outside of Firefox, select Properties. On that window, the type of file will be "Firefox HTML Document (. pdf)". That means that the file is still a PDF file, but that Firefox is just the default reader in Windows.

Why are pdfs not opening in Firefox?

If you can't open any PDF files with the built-in PDF viewer, a Firefox extension could be the cause. You can disable all of your extensions, to see if one of them was the problem. For details, see Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems.


2 Answers

You can just write the link to the pdf directly into the data attribute like this:

<div id="embeddedPdfContainer"><object data="/download-pdf/some.pdf" id="embeddedPdf"  width="820"  height="1135" type="application/pdf"></object></div>

I tested it with Chrome and Internet Explorer (different versions) and it works

If you want to stay with the c:url option you should change the second " to '

so changing this:

"<c:url value="/download-pdf/${id }"/>"

into this:

 "<c:url value='/download-pdf/${id }'/>"

in order to not "escape" the string

like image 149
Inspyro Avatar answered Sep 19 '22 17:09

Inspyro


When you deliver dubious HTML:

<div id="embeddedPdfContainer"><object data="<c:url value="/download-pdf/${id }"/>" id="embeddedPdf"  width="820" height="1135" type="application/pdf"></object></div>
                                            ^      ^
                                            |      |
                                          Start   End?

... browsers try to figure out what you had in mind, with a varying degree of success that depends on the algorithms they implement and how imaginative the webmaster is. Different browsers can't always agree on how to handle valid code (where there're clear rules and specs) so it's to expect that the level of disagreement increases with invalid code.

IMHO, the simplest path to obtain cross-browser compatibility is to generate valid code. As help, you can use the on-line W3C HTML validator or whatever equivalent tool your IDE provides.

like image 30
Álvaro González Avatar answered Sep 19 '22 17:09

Álvaro González