File opens instead of downloading in internet explorer in a href link

前端 未结 8 1838
萌比男神i
萌比男神i 2020-11-30 11:13
filename\'

When i click the link, my filename.xxx should be downloa

相关标签:
8条回答
  • 2020-11-30 11:24

    This is not a code issue. It is your default IE settings

    To change the "always open" setting:

    1. In Windows Explorer, click on the "Tools" menu, choose "Folder options"
    2. In the window that appears, click on the "File Types" tab, and scroll through the list until you find the file extension you want to change (they're in alphabetical order). For example, if Internet Explorer always tries to open .zip files, scroll through the list until you find the entry for "zip".
    3. Click on the file type, then the "Advanced" button.
    4. Check the "Confirm after download" box, then click OK > Close.

    EDIT: If you ask me , instead of making any changes in the code i would add the following text "Internet Explorer users: To download file, "Rightclick" the link and hit "Save target as" to download the file."

    EDIT 2: THIS solution will work perfectly for you. Its a solution i just copied from the other answer. Im not trying to pass it off as my own

    Content-Type: application/octet-stream
    Content-Disposition: attachment;filename=\"filename.xxx\"
    

    However you must make sure that you specify the type of file(s) you allow. You have mentioned in your post that you want this for any type of file. This will be an issue.

    For ex. If your site has images and if the end user clicks these images then they will be downloaded on his computer instead of opening in a new page. Got the point. So you need to specify the file extensions.

    0 讨论(0)
  • 2020-11-30 11:27

    It should be fixed on server side. Your server should return this headers for this file types:

    Content-Type: application/octet-stream
    Content-Disposition: attachment;filename=\"filename.xxx\"
    
    0 讨论(0)
  • 2020-11-30 11:31

    For apache2 server:

    AddType application/octect-stream .ova
    

    File location will depend on particular version of Apache2 -- ours is in /etc/apache2/mods-available/mime.conf

    Reference:

    https://askubuntu.com/questions/610645/how-to-configure-apache2-to-download-files-directly

    0 讨论(0)
  • 2020-11-30 11:32

    It is known HTTP headers problem with Internet Explorer. Try to edit your server's .htaccess file (if you use Apache) and include the following rules:

    # IE: force download of .xxx files
    AddType application/octect-stream .xxx
    <Files *.xxx>
      ForceType application/octet-stream
      Header Set Content-Disposition attachment
    </Files>
    
    0 讨论(0)
  • 2020-11-30 11:42

    The download attribute is not supported in IE (see http://caniuse.com/#search=download%20attribute).

    That suggests the download attribute is only supported by firefox, chrome, opera and the latest version of blackberry's browser.

    For other browsers you'll need to use more traditional methods to force download. That is server side code is necessary to set an appropriate Content-Type and Content-Disposition header to tell (or trick depending on your point of view) the browser to download the item. Headers should look like this:

    Content-Type: application/octet-stream
    Content-Disposition: attachment;filename=\"filename.xxx\"
    

    (thanks to antyrat for the copy and paste of the headers)

    0 讨论(0)
  • 2020-11-30 11:42

    This must be a matter of http headers.

    see here: HTTP Headers for File Downloads

    The server should tell your browser to download the file by sending

    Content-Type: application/octet-stream; 
    Content-Disposition: attachment;
    

    in the headers

    0 讨论(0)
提交回复
热议问题