Clicking a download link in Safari causes all target=_blank links to download when clicked, is there a workaround?

后端 未结 2 613
隐瞒了意图╮
隐瞒了意图╮ 2021-02-15 17:53

Issue: After clicking on a link that downloads content, all other links that have target=\"_blank\" and no download attr download when clicked instead of openin

相关标签:
2条回答
  • 2021-02-15 18:47

    With regards to your issue mention above, you have a couple of option to download a file:

    Open file in same window:

    <a href="sample.txt" target="_self">Click to Download</a>
    

    Open file in new window:

    <a href="sample.txt" target="_blank">Click to Download</a>
    

    Force file download window:
    However, if you want to force the file to download, by prompting a download pop-up box (to open or save), then all you need to do is add ‘download’ to the link as seen below:

    <a href="sample.txt" download>Click to Download</a>
    

    Therefore, your edited code could look something like this:

    <!DOCTYPE html>
    <html>
    
      <head>
        <link rel="stylesheet" href="style.css">
        <script src="script.js"></script>
      </head>
    
      <body>
        <h3>Instructions</h3>
        <ul>
          <li>Click <a href='sample.txt' target='_blank'>ME</a> (download NOT present) to see page load in new tab then come back to this page</li>
          <li>Click <a href='sample.txt' download='sample.txt'>ME</a> (download PRESENT) to see it downloaded</li>
          <li>Click <a href='sample.txt' download>ME</a> (download NOT present).  Safari forces this link to download</li>
        </ul>
      </body>
    
    </html>
    

    Hope this helps you!

    0 讨论(0)
  • 2021-02-15 18:47

    Not really an answer, but after reporting the issue to apple and waiting, we now have Safari 11.1.1 which seems to have resolved the issue, so marking resolved.

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