Jump to content

[Solved] Open PDF in New Window?


Recommended Posts

Is it possible to open product attachments in a new window instead of downloading?

 

I tried adding

target="_blank"

to this line

<a href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")}">{$attachment.name|escape:'htmlall':'UTF-8'}</a>

in product.tpl.

 

It shows up in the code, but doesn't actually work. Is there some other way to do this?

Edited by AnonymousUser (see edit history)
Link to comment
Share on other sites

it is likely the method used by the attachment controller that is forcing the content to be downloaded. you would need to ensure the mime type of the attachment is being set properly, and that the client viewing the attachment has an associated program to open the file.

 

what type of file are you attaching?

Link to comment
Share on other sites

I'm attaching PDFs. All browsers that I can think of have some action associated with opening a PDF, whether it's a prompt to download/open or just open, send to an external program and open, etc. I would like to respect that decision instead of force-downloading, if that makes sense.

 

Is there anyway that you know of to adjust how the controller handles these files? (I know that may be asking much, so if you don't, that's fine.)

 

I'm not sure how to check the MIME type, but I've never had any sort of problem with PDFs on other platforms I've used. If that's relevant, can I get any pointers?

Link to comment
Share on other sites

assuming you are using PS v1.5.4.1, looks like you simply need to change the AttachmentController.php

 

from

header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"');

 

to

header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"');

 

It would be best to do this as an override. I'm also not sure how this will react to non-PDF attachments, so you best test them before you release them to the public

  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...

Hi, I have Prestashop v.1.6.1.4 and this solution is not working for me in Google Chrome or Firefox (even after clearing Prestashop & even browser cache). It is however only opening files in Microsoft Edge. When I comment out the header line, it tries to download index.php right away.

 

Is there more than this line that must be editied in AttachmentController.php file to make it work?

header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"');

 

Sample page:

http://dar-us-salam.com/english-books/biography-history/prophet-muhammad-s/the-sealed-nectar-ar-raheeq-al-makhtum.html

Link to comment
Share on other sites

  • 2 weeks later...

I have tested this in Firefox, Chrome, IE and Edge and it works properly for me.

 

There are 2 changes to be made....

 

1) Change or override the AttachmentController.php so that it uses Content-Disposition inline instead of attachment.  This will instruct the browser to show the file contents in a browser window, instead of downloading

header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"');

2) If you want the browser to show it in a new window/tab, then you need to change the anchor to include target="_new". 

 

 

Note: You have to realize however, that the browser cannot show the contents of a file, unless that browser knows how to do that.  So if the file attachment is a PDF, then you need to have a PDF reader extension installed in the browser.  If the file is a zip file, it has to be downloaded, there is no way to show that in a browser

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

 

Hello,
On opening the file in a new tab:
2) If you want the browser to show it in a new window / tab, then you need to change the anchor to include target = "_ new".
Could you specify which file to be edited.
Regards,
Decho Minkov

 

 

I need an help too!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...