I recently encountered a similar situation and decided to create a user-friendly webpage that allows for easy downloading of data as a text file, specifically in CSV format. My approach involved utilizing Javascript and exploring the potential of data:
URIs.
//By first constructing the csvOutput using Javascript
var popup = window.open("data:application/octet-stream," + encodeURIComponent(csvOutput), "child");
//There is no need to use document.write() within the child window
In my experience with Firefox, the method mentioned above did not result in a new window popping up but rather prompted the user to save the file as a .part file. While not perfect, it achieved the goal without unnecessary interruptions.
An alternative approach involves using the text/plain MIME type:
//By initialising the csvOutput through Javascript
var popup = window.open("data:text/plain;charset=utf-8," + encodeURIComponent(csvOutput), "child");
This method, when tested on Firefox, did indeed open a new window where the data was saved by default as ASCII text, free from any unwanted elements or formatting inherited from the parent window. This solution seemed more promising for my needs.
However, it is worth noting that this strategy may not be compatible with Internet Explorer (IE). Only IE 8 supports data:
URIs and imposes certain limitations on their usage. For IE users, an alternative like execCommand might be considered.
Credit goes to resources such as a helpful tek-tip thread and insightful articles like the one detailing the data URI scheme on Wikipedia.