Open file from local system and save changes to file that opened
in this example we are try with txt file:
Ctrl + s
add this code as follows:
window.addEventListener("keydown" , e => { if (e.key === 's' && e.metaKey) { e.preventDefault(); savefile(); } });
return to first exemple:
let editor = document.getElementById("editor"); const openfile = async () => { [fileHandle] = await window.showOpenFilePicker(); const file = await fileHandle.getFile(); const contents = await file.text(); editor.value = contents; } const savefile = async () => { const writable = await fileHandle.createWritable(); await writable.write(editor.value); await writable.close(); } window.addEventListener("keydown" , e => { if (e.key === 's' && e.metaKey) { e.preventDefault(); savefile(); } });

© Manajmnt code
Comments
Post a Comment
message