The best way to do this is indeed by constructing an iframe and triggering the download from there.
I have tested this in Chrome, IE6+ and Firefox and this approach seems to work in all of them.
Example code:
function DownloadFile(filePath) {
var downloadIframe = $('<iframe />',
{
id : 'downloadIframe'
}).appendTo('body');
downloadIframe.attr('src', filePath);
}
This will only work properly for a one off download (as we've hard coded an id), if you are triggering multiple downloads, then I suggest you reuse the iframe by storing it in a more widely accessible variable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…