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

前端 未结 8 1869
萌比男神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.

提交回复
热议问题