How do I get PDF downloads to happen in the background instead of in the current browser window?

How do I get PDF downloads to happen in the background instead of in the current browser window?
With static websites I had a PHP script in between, which worked perfectly and the link was built like this:

www.mywebsite.com/download.php?file=catalogue.pdf

Is it possible with Kirby to interpose a PHP script with the following link structure?

<a href="download.php?file=<?= $pdf->url() ?>" ...

If so, in which folder is this script placed (assets?)?

I’d use a route for this purpose, if using a download attribute on the anker element is not sufficient.

If you want to call a php file, it must live in a publicly accessible folder, e.g. in assets.

1 Like

Thank you texnixe for your advice. I have not yet dealt with routes, because as a newcomer I first want to deal with less complex techniques. The understanding grows with time. Then I dare myself also to more profound solutions.
I will first try the way to make the script accessible via the assets folder. <?= $pdf->url() ?> creates only the link, but no special handling for downloads, right?

That code as such only prints the URL, when used within an href attribute, it links to the file.

Shouldn’t it be enough to

<a href="<?= $file->url() ?>" download>Download me</a>
1 Like

Doesn’t this work for you?
<a href="<?= $pdf->url() ?>" download target="_blank">

1 Like

The download-attribute (I did not know at all) is the right solution for me. The additional PHP script is therefore superfluous. Thanks a lot!