Force browser to open file instead of prompting download

前端 未结 3 2535
孤独总比滥情好
孤独总比滥情好 2021-02-20 18:49

When clicking a PDF link in Firefox and Chrome, the file will sometimes be opened for in-browser viewing and sometimes prompt a \"Save as\" dialog.

If I wanted to force

相关标签:
3条回答
  • 2021-02-20 19:22

    I'm using Firefox in XP. I went to the OPTIONS under Tools and found Portable Document Format. Click on it and it will allow you to change the way PDF files are handled.

    0 讨论(0)
  • 2021-02-20 19:36

    open the file in a Microsoft Word and save as html.

    0 讨论(0)
  • 2021-02-20 19:40

    You can achieve that by setting the appropriate header (for instance, in case of PDF, the header will be Content-type: application/pdf;

    With this header, the browser will know the mime-type of the file and display it if it is compatible with it.

    Here you can see the headers for a PDF.
    As a hint, what I like to do is to use some sort of controller (in case you are using a backend language) that handles the download. Hence, to download myNewProject.pdf I do

    <a href='download.php?file=myNewProject.pdf&viewInBrowser=1'>Download!</a>
    

    Then I can set the appropriate headers depending on the file type, or if I want to force download or view it in the browser...

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