How to force mime-type of file download
When users visit our website's download page, it automatically starts the download. The page has a display:hidden
iframe with src
pointing to the installer file
<iframe src="/path/to/installer.dmg"></iframe>
This works fine so far. But my Chrome extension: "Web developer" logs this Warning message
Resource interpreted as Document but transferred with MIME type application/octet-stream
So, is there a way to explicitly declare installer.dmg's content-type as octet-stream, so that browsers do not get confused?开发者_StackOverflow中文版
As one of the previous answers references a broken link I will give my answer here.
If you are trying to specify the mime type of files with a certain extension you can add this to .htaccess:
AddType application/octet-stream .dmg
However, this will not guarantee that browsers will 'download' the file. Chrome for example does not recognise this. So here is a way to force files of a certain type to 'download':
<FilesMatch "\.(?i:dmg)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
The little bit of regex around the extension (dmg) is just there to make it case insensitive.
You might need to clear browser cache before it works correctly.
This works in the latest Chrome, Firefox and IE8 (as of August 2013). I have not tested in the latest IE or Safari, so if someone has those browsers and can test them, please confirm they work in the comments below.
Insert those lines in your vhost configuration, inside a docroot directory:
<Directory path/of/your/docroot/directory>
<Files path/of/your/file>
Header set Content-type "mime/type"
</Files>
</Directory>
This page has what you need, if your web server is Apache. Basically what you do is tell apache that any file with a .dmg extension has the mime-type of application/octet-stream.
The problem is that you are using an installer file as a web page what you can do is open the installer page in a popup on document ready you can read this (with jquery): http://choosedaily.com/1178/15-jquery-popup-modal-dialog-plugins-tutorials/ or this(no jquery): http://www.quirksmode.org/js/popup.html
精彩评论