Possible with JavaScript?

Am I correct in my thinking that JavaScript can write a text file but cannot send and a hotkey combination like Ctrl + s or launch an executable file on a Windows or Mac system?

Hi @pctechtv1, you shouldn’t override default browser hotkeys such as ctrl + s (which is usually used to save the current page), but you can create a download link for your text file using a data URI:

<textarea id="text"></textarea>
<a href="data:," id="download" download="my-text.txt">download</a>
const text = document.getElementById('text')
const download = document.getElementById('download')

text.addEventListener('change', () => {
  download.href = 'data:,' + encodeURIComponent(text.value)
})

As for executables, no that’s not possible; how and when system applications are getting executed is a matter of the user agent preferences.

1 Like

Why “,” after “data:”?

It’s simply how the scheme is defined – the data comes after the comma:

1 Like

Launching an executable file ? Boy, it sounds a security nightmare !