encho Posted May 2, 2024 Share Posted May 2, 2024 One of the fields that I have is 'files' - a self-exlanatory multiple-files type of field, used mostly for PDFs. When I click on the file title in the backend it used to open this file in a new tab (using the browser's built-in PDF viewer). Somewhere in the last few updates I did, this behaviour changed and now the files are automatically downloaded. How to manipulate this, I assume it is a matter of adding target='_blank' to somewhere in the code, but not show where? Again, this is for the backend/admin area of the website only. I am aware that you can do this with right mouse click (and old cmd or ctrl click doesn't work either) but it is not fully streamlined for my specific use case. Any suggestions welcome. Link to comment Share on other sites More sharing options...
bernhard Posted May 2, 2024 Share Posted May 2, 2024 You can use this hook to do what you want: $wire->addHookBefore("InputfieldFile::render", function (HookEvent $event) { $inputfield = $event->object; if ($inputfield->name !== 'your_fields_name') return; $inputfield->appendMarkup .= "<script> document.currentScript.parentElement.querySelectorAll('a.InputfieldFileName').forEach(function(link) { if (!link.href.endsWith('.pdf')) return; link.removeAttribute('download'); }); </script>"; }); 1 1 Link to comment Share on other sites More sharing options...
encho Posted May 2, 2024 Author Share Posted May 2, 2024 Thanks @bernhard for being awesome again. This worked flawlessly! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now