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

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
});
});