title: Creating a temporary file and opening it in a different app on the user's computer
body: <p>I'm coding an internal corporate website that, among other things, produces and renders XML files. These files generally aren't meant to be saved directly, and the user should rarely need to view them raw in the first place. However, the site can download and open a file in an XML processor installed on the user's computer.</p>
  <p>The website was originally written for Internet Explorer 6, and I'm trying to upgrade it to be compatible with modern browsers. The code it initially used, compatible with IE6, was this:</p>
  <pre><code>function XmlOpen(path) { // path = &quot;C:/Program Files/path/to/executable.exe&quot;, hardcoded
      // xmlOutput is a global variable containing the raw XML to be saved
      if (xmlOutput) {
          // global variable to cache most recently downloaded file. If the XML is regenerated
          // this will be reset
          if (!xmlTempPath) {
              var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
              var tempfolder = 2;
              var tfolder = fso.GetSpecialFolder(tempfolder);
              var tname = fso.GetTempName();
              var tempfile = tfolder.CreateTextFile(tname);
              tempfile.writeline(xmlOutput);
              tempfile.close();
              xmlTempPath = tfolder.Path + '\\' + tname;
          }
          var shell = new ActiveXObject(&quot;WScript.Shell&quot;);
          var cmd = '&quot;' + path + '&quot; &quot;' + xmlTempPath + '&quot;';
          shell.Run(cmd);
      }
      return false;
  }
  </code></pre>
  <p>Ideally, my requirements for the rewrite are that it require as little user interaction as possible beyond the initial click.</p>
  <p>My basic approach is to, instead of using ActiveXObjects, use registry keys to tag the appropriate XML programs. These can be installed during onboarding, when also installing all our other internal tools, so I figure I should just be able to open a url as <code>xmlprogram://filename</code> and have it work, as long as I have a file to go with it.</p>
  <p>I can also easily download a file, by just writing the XML into a blob, generating a random filename, and having a download prompt appear. But then I don't know the folder and actual name with which the file was downloaded, so I can't automatically have it open with the <code>xmlprogram://</code> url. Thus, I need to somehow save the file temporarily somewhere my javascript knows the full path to, and invoke the user's program on it using the link. But from what I've been able to find, it's presently impossible to write an actual temporary file on the user's computer, and you can't make localstorage be treated as a file.</p>
  <p><strong>tl;dr How do I save a temporary file to the user's computer such that I know the location to which it was saved and can have them open it in a different program automatically?</strong></p>