Display the PDF file in new tab instead of "SAVE" download prompt.

  • Posts: 5
  • Thank you received: 1
5 years 5 months ago #257970

-- url of the page with the problem -- : palazzetti.ca/shop/bedroom/product/15-na.../category_pathway-46
-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.5
-- Browser(s) name and version -- : Safari
-- Error-message(debug-mod must be tuned on) -- : Display PDF instead of download

Every product in our web site has one or more PDF's. They are uploaded as "files".
We want to click on a PDF and get it automatically to open another tab and display the PDF, rather than having the prompt to SAVE the PDF.

Or, if there is a prompt, we should have a custom one with 3 options: 1) SAVE 2) Open and display in new tab 3) cancel

Does anyone know how to do this?

The following user(s) said Thank You: neimar

Please Log in or Create an account to join the conversation.

  • Posts: 75529
  • Thank you received: 11766
  • MODERATOR
5 years 5 months ago #257984

Hi,

The Files feature of HikaShop is to allow customers/users to download the files. So of course, it forces the download.
If you want to change that, you'll have to change the content-type header sent by HikaShop.
There are two ways you can do it:
1. You edit the lines:
header('Content-Type: application/octet-stream');
to:
header('Content-Type: application/pdf');
in the file administrator/components/com_hikashop/classes/file.php
It's easy to do, but there are several downsides: You'll loose the change when you update and it won't support other file types properly.
2. You can create a custom Joomla plugin of the group "hikashop" implementing the trigger onBeforeDownloadFile(&$filename, &$do, &$file, $options) in your plugin and sending the file yourself to the user based on the data provided by HikaShop to the trigger function in your plugin. You can read more about creating plugins here:
www.hikashop.com/support/documentation/6...mentation.html#intro

The following user(s) said Thank You: neimar

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
3 years 10 months ago #295121

Hi,

first option not working for me. Hika still downloading file instead of opening pdf in browser.
Can you help me for this problem?

Please Log in or Create an account to join the conversation.

  • Posts: 75529
  • Thank you received: 11766
  • MODERATOR
3 years 10 months ago #295145

Hi,

Well, I didn't expand on this.
This modification actually doesn't change the way your browser with behave directly.
What this modification changes, is that the browser knows that the file it is downloading is a PDF file instead of a random file.
Knowing that, the browser, based on how you configured it, will download or open the file.
Now, you can also change the line:
header('Content-Disposition: attachment; filename="' . $name . '"');
to:
header('Content-Disposition: inline; filename="' . $name . '"');
in order to ask the browser to try to open the file rather than its default action for the file type you're sending.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
3 years 10 months ago #295208

It's working

tnx

Please Log in or Create an account to join the conversation.

  • Posts: 860
  • Thank you received: 9
  • Hikamarket Multivendor Hikashop Business
5 months 2 weeks ago #337779

Hi,

I tried this but it opens the files in the same window istead of a new.

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 75529
  • Thank you received: 11766
  • MODERATOR
5 months 2 weeks ago #337781

Hi,

Yes.
The code change I gave before is to open the file in the browser instead of downloading it.
If you want it to be in a new tab, you need to change the line:

$files[] = '<a class="hikashop_product_file_link" href="' .  $file->download_link . '">' . $file->file_name . '</a>';
to:
$files[] = '<a class="hikashop_product_file_link" target="_blank" href="' .  $file->download_link . '">' . $file->file_name . '</a>';
in show_block_product_files.php via the menu Display>Views, supposing that you're also talking about the download links on the product details page.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

Time to create page: 0.085 seconds
Powered by Kunena Forum