Skip to content Skip to sidebar Skip to footer

Prevent Browser From Prompting For File Download When Opening CSS File In IFrame?

I have a web app which loads an arbitrary page or file into an iFrame. Under some browsers, when pointing the iFrame's src to a css file, instead of displaying the css text, a 'dow

Solution 1:

For verbatim display of the file as plain text, I would just send it as

Content-Type: text/plain; charset=utf-8

Solution 2:

Within your web app you could have a page (in whatever language you're using, assuming that you're not serving up solely static files) that takes a parameter which is the path of the file you want to view and then load that in the IFRAME

So rather than setting the IFRAMEs src to "somefile.css" (or whatever file it is), set the src to "FileViewer.php?filepath=/somefile.css" (replace .php with the language of choice), and then have the FileViewer page load the file from the filesystem and render it out but with a Content-Type set.


Post a Comment for "Prevent Browser From Prompting For File Download When Opening CSS File In IFrame?"