I have a Templates document library, where the piece of code below has happily forcing the download of a template document instead of the file been opened. However, it has stopped working.
The reason for needing to force download is that users actually need a copy of the template and don't need to open the actual original template. (There is an approval workflow, as part of a QMS, which manages the templates and tracks the version, users accidentally interfere with this otherwise).
If any user clicks on a file name currently they see this error message (which isn't really telling us anything, other than the code is not rerouting the 'open file' request to a 'download document' request:
Here is the code that is being used:
n.b. there is a Templates Editors group for certain users who have permission to edit the templates in order to keep them updated. For everyone else -> force download.
Following Ahmad's suggestion to check the Console - there is a warning of 'deprecation' - it appears that my custom .js code is being ignored by the browser somehow. I've never seen this happen before, but I also didn't know the console existed (so what do I know...).
I did a search on the warning message and found this popular link. Possibly the code needs to load via AJAX instead of in the Style Library? There are quite a few Answers in this post, but a lot of it I don't understand, since I am a humble SP Admin who only dabbles in modifying & reusing existing code.