Skip to main content
fixing a mistake
Source Link

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons or keyboard shortcuts I think. Like CTRL + B to embolden selected text. It doesn't have any safety checks as of yet, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

HTA's do have other disadvantages too. By default theyThey don't support ES6 (though I think the registry can be changed to use the new MSEdge-webview rendering stack instead, which will enable support for ES6transpiling is an option).

Although it is a bit dated, If you're not trying to use modern web features, I think you'll agree that it is very functional and usable.

Edit I forgot to mention, but HTAs have to be saved with the .hta file extension for mshta.exe to be registered as their file type handler. Which is needed so that you can double click it in windows explorer to open it easily.

See also

Introduction to HTML Applications on MSDN

HTML Applications reference on MSDN

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons or keyboard shortcuts I think. Like CTRL + B to embolden selected text. It doesn't have any safety checks as of yet, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

HTA's do have other disadvantages too. By default they don't support ES6 (though I think the registry can be changed to use the new MSEdge-webview rendering stack instead, which will enable support for ES6).

Although it is a bit dated, I think you'll agree that it is very functional and usable.

Edit I forgot to mention, but HTAs have to be saved with the .hta file extension for mshta.exe to be registered as their file type handler. Which is needed so that you can double click it in windows explorer to open it easily.

See also

Introduction to HTML Applications on MSDN

HTML Applications reference on MSDN

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons or keyboard shortcuts I think. Like CTRL + B to embolden selected text. It doesn't have any safety checks as of yet, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

HTA's do have other disadvantages too. They don't support ES6 (though transpiling is an option).

Although it is a bit dated, If you're not trying to use modern web features, I think you'll agree that it is very functional and usable.

Edit I forgot to mention, but HTAs have to be saved with the .hta file extension for mshta.exe to be registered as their file type handler. Which is needed so that you can double click it in windows explorer to open it easily.

See also

Introduction to HTML Applications on MSDN

HTML Applications reference on MSDN

Added disadvantages of HTAs, and how to get them working properly, and reference materials.
Source Link

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons or keyboard shortcuts I think. Like CTRL + B to embolden selected text. It doesn't have any safety checks eitheras of yet, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

HTA's do have other disadvantages too. By default they don't support ES6 (though I think the registry can be changed to use the new MSEdge-webview rendering stack instead, which will enable support for ES6).

Although it is a bit dated, I think you'll agree that it is very functional and usable.

Edit I forgot to mention, but HTAs have to be saved with the .hta file extension for mshta.exe to be registered as their file type handler. Which is needed so that you can double click it in windows explorer to open it easily.

See also

Introduction to HTML Applications on MSDN

HTML Applications reference on MSDN

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons I think. It doesn't have any safety checks either, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons or keyboard shortcuts I think. Like CTRL + B to embolden selected text. It doesn't have any safety checks as of yet, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.

HTA's do have other disadvantages too. By default they don't support ES6 (though I think the registry can be changed to use the new MSEdge-webview rendering stack instead, which will enable support for ES6).

Although it is a bit dated, I think you'll agree that it is very functional and usable.

Edit I forgot to mention, but HTAs have to be saved with the .hta file extension for mshta.exe to be registered as their file type handler. Which is needed so that you can double click it in windows explorer to open it easily.

See also

Introduction to HTML Applications on MSDN

HTML Applications reference on MSDN

Source Link

If you are fine with your code running outside of the scope of your default browser, and you are fine with windows only support, HTAs meet the silently save without prompts requirement easily.

The below code doesn't use many HTA specific features but it does still use microsoft specific stuff like ActiveXObject("Scripting.FileSystemObject").

<html>

<head>
  <title>Simple Notepad</title>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <script>
    document.addEventListener('keydown', function (event) {
      if (event.ctrlKey) {
        if (event.key == 's') {
          var FSo = new ActiveXObject("Scripting.FileSystemObject");
          //see https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/opentextfile-method
          var thisFile = FSo.OpenTextFile(window.location.pathname, 2, true, -1);
          thisFile.Write(document.getElementsByTagName("html")[0].outerHTML);
          thisFile.Close();
          // Comment out the below alert to get truly silent saving.
          alert('Saved Successfully');
          if (event.preventDefault) event.preventDefault();
          return false;
        }
      }
    }, false);
  </script>

</head>

<body contentEditable="true">
  <h1>Press <kbd>CTRL + S</kbd> To Save</h1>
</body>

</html>

It also isn't a very rich editing experience but that can be fixed with some more buttons I think. It doesn't have any safety checks either, but binding an event handler to beforeunload should prevent any data loss caused by accidentally closing the program.