Haradzieniec
Haradzieniec

Reputation: 9340

html: open pdf and png in the browser, not to download it

The code on the html page is:

<a href="getReport.php?id=123">View report in a new window</a>

Once any user clicks on it, it becomes downloaded (it is a .png file) by his browser and he is able to view it.

How can we make it opened in a new window instead?

Upvotes: 1

Views: 4526

Answers (3)

Pandian
Pandian

Reputation: 9126

In anchor tag give the URL of the PDF embedded page and In the PDF Embedded page, try iFrame to display the PDF, It will work

PDF IFrame :

<iframe src="http://docs.google.com/gview?url=http://ocw.mit.edu/courses/mechanical-engineering/2-000-how-and-why-machines-work-spring-2002/tools/html.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Fiddle : http://jsfiddle.net/RYh7U/69/

IMAGE IFrame :

<iframe src="http://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg">
</iframe>

Fiddle : http://jsfiddle.net/RYh7U/70/

Upvotes: 3

paulsm4
paulsm4

Reputation: 121599

Q: Do you mean "getReport.php?id=123" isn't rendering as a .png image (it's asking the user to download)? Or is it displaying as an image, but you want it to display in a new, separate window?

If the former, you need to make sure the server sends the correct Content-type (e.g. "image/png").

If the latter, just do a Javascript "window.open()" (or equivalent)

======== UPDATE =======

My 1990's heritage with Javascript 1.2 is catching up with me :) Don't use "window.open()" - do as Pandian says and use if you want to implement a pop-up window. Here are more details:

By the same token, your question is vague. If the problem is that the file is asking you to "download" (if the image isn't appearing anywhere), then your PHP program isn't sending the file correctly. At a minimum, it must set "Content-type" before it sends the binary .png data.

'Hope that helps...

Upvotes: 2

Barmar
Barmar

Reputation: 780655

<a href="#" onclick="window.open('getReport.php?id=123', '_blank')">View report in a new window</a>

Upvotes: 0

Related Questions