I have an HTML document stored on a server (as an attachment on a Google Sites site) with a link to it from my web page. When i click the link it downloads the document rather that opening it in the browser. Does anyone know of a way to set it so it will open in the browser r开发者_运维知识库ather than downloading it? It's a Google Sites site so I am somewhat limited to basic html code... Any ideas would be much appreciated! Thanx!
You'd have to manipulate HTTP headers to do this. So you probably won't do this without downloading the file and resending the headers.
HTML, images, audio are (when requested by a browser) told by a server what type of file it is. The server is configured to identify the type of file and give this result back to the browser who decides what to do with this result (e.g. downloading, showing etc.). Most browsers will if the result is not recognized offering the option to download a file.
You can use a Content-disposition header (google it) which tells the browser how to handle the file (inline is in the browser, attachment is download)
When the browser requests a document (hypertext, image, audio, multimedia, etc.), the server tells the browser what type of file it is. The server should be configured to identify a document's media type properly. Something like header("Content-Disposition: attachment; filename=filename.html");
(this is php, google your own language) this brings some security implications (see RFC)
Most browsers will work though with this content-disposition option. What you can do also is "application/octet-stream". This says something to the browser like: "I'm a file with a nothing extension" so the browser then decides to do the default extension which is in most cases downloading the file. Something like:
<meta http-equiv="content-type","application/octet-stream">
<meta http-equiv="content-disposition","attachment; filename=filename.html">
This is known not always to work in IE.
Best solution is create a custom Mime-type and define this in your server settings. Something like this can be done in IIS or apache.
A long story but i hope it will help you.
精彩评论