-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Per me sarebbe comodo intercettare i tasti in modo che, quando si è su desktop e si visualizza un file PDF, premendo CTRL + S venga scaricato il PDF anziché l'HTML della pagina.
Si può intercettare il CTRL + S così, anche se con un po' di prove ho visto che non funziona all'interno dell'iframe del PDF viewer (quindi il focus dev'essere fuori dall'iframe).
Un modo estremamente crudo è
document.addEventListener('keydown', e => {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
downloadPdf();
}
});
function downloadPdf() {
const pdfUrl = 'url-al-pdf';
fetch(pdfUrl, { mode: 'cors' }) // esempio con fetch
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'nome-file.pdf');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
});
}
Non è una cosa importante, giusto un nice to have di bassissima priorità
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
New