Content Disposition Typo

While doing a quick patch for XLS generation (caused by Microsoft’s security change for Excel 2007+) in which I swapped a clients code from generated HTML to using the POI lib I ran into this fun little browser discrepancy :

If I want to name the file I’m generating and returning to the browser for download, I just set the “Content-Disposition” header thus:

var fileName = workbookName +".xls";
pageResponse.setHeader("Content-Disposition","inline; filename=" + fileName);

Works just fine on Chrome/Safari and even the dreaded IE, but is completely ignored by firefox

<scratch scratch> …. <shrug> if in doubt use more quote marks

var fileName = workbookName +".xls";
pageResponse.setHeader("Content-Disposition","Attachment; filename="" + fileName + """);

That’s better works everywhere now 🙂
(Yes I am aware that the quoted version was the one I should have used in the first place as per [w3 Protocols](http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html) but, if the number of examples that don’t have them in is any judge then I was not alone and browser consistency would still be a nice thing)

Leave a Reply

Your email address will not be published. Required fields are marked *