Allow PDF Files to Open Natively via Browser as Opposed to in Modal

I would like to be able to have PDF files clicked in Knack open natively with the browser, as opposed to being locked behind a modal.

We use a section of Knack for document storage. Whenever a user clicks on a (PDF) filename in a table, it opens in a modal. This is often slow, and for whatever reason, frequently requires closing the modal and clicking a second time before the PDF will actually open. We also have internal websites we use which require the “Always download PDF files” option in Microsoft Edge to be active. This option does not work with Knack modals (PDFs will not open at all in the modal). Allowing the PDF to be handled natively by the browser should alleviate these issues.

Thanks.

Was there ever a solution to this?

There was not unfortunately.

Hi @Eddie and @jason,

I have flagged this feature request with our product team for consideration in future sprints. Thank you for sharing!

Les,

The pdf modal viewer was working perfectly on mobile until this weekend. Is this something that is being looked into? Right now we don’t have a good way to access these files.

Hi Eddie

We have used the solution in this thread here:

It opens the file in a separate tab but it allows all files to be opened.

Craig

Thank you,

I ended up going with this solution (Credit Stephen Chapman):

StephenChapmanKnack Expert

Oct 2019

You’re in luck! I wrote this code a little while ago, hopefully it still works. This will automatically display a PDF/image file or start downloading any other file once clicked, rather than display in the preview window. All you need to do is replace {YOUR APPLICATION ID} with your app’s ID.

$(document).on(‘knack-scene-render.any’, function (event, view, data) {
$(“a.kn-view-asset”).on(“click”, function(e) {
e.preventDefault(); //Prevent normal file window opening
e.stopPropagation();
var url = $(this).attr(‘href’); // Get the URL of the clicked link
var pathArray = url.split(‘/’); // Split the URL string into substrings between ‘/’ characters
var filePath = pathArray[pathArray.length-1]; // Get the file name in the last substring (e.g. file.pdf)
var assetPath = pathArray[pathArray.length-2]; // Get the asset path in the second-last substring (e.g. 6-13-77-5d2ffb2f47b3c70010ffd98d)
pathArray = assetPath.split(‘-’); // Split the assetPath into substrings between ‘-’ characters
assetPath = pathArray[pathArray.length-1]; // Get the actual asset path in the last substring (e.g. 5d2ffb2f47b3c70010ffd98d)
var newURL = “https://api.knack.com/v1/applications/{YOUR APPLICATION ID}/download/asset/” + assetPath + “/” + filePath // Concatenate the download URL
window.open(newURL, ‘_blank’); // Open the new URL in a new tab
});
});

Hi @Eddie,

Thank you for bringing this to my attention! I checked into this and our engineering team is currently investigating this issue as it has been reported by a few others.

I’ll be happy to update you in this thread when the issue is resolved. Sorry for the inconvenience!