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.
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:
function XmlOpen(path) { // path = "C:/Program Files/path/to/executable.exe", 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("Scripting.FileSystemObject");
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("WScript.Shell");
var cmd = '"' + path + '" "' + xmlTempPath + '"';
shell.Run(cmd);
}
return false;
}
Ideally, my requirements for the rewrite are that it require as little user interaction as possible beyond the initial click.
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 xmlprogram://filename and have it work, as long as I have a file to go with it.
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 xmlprogram:// 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.
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?