Help me to understand. There is a link to download the file (program). If you assign the attribute target = "_ blank" to it, then when you click in all browsers, a new empty tab opens, then the file download starts and the tab closes automatically. This works everywhere except for the Edge browser. There, the tab remains open, and the dialog for saving the downloaded file appears in the previous tab.

An example can be seen here (link "from the developer site" and below are more links):

http:// www.softportal.com/get-44132-picotorrent.html 

But I also found sites on which there is no such problem, and I don’t understand why. Here is an example:

 http:// newprograms.ru/downloads-hamachi.html 

Here in the Edge, the empty tab does not remain hanging open, it closes as well as in other browsers. Why, what is the difference, how to do also?

    1 answer 1

    Just use the download attribute.

     <a download="text.txt" href="data:application/octet-stream,hello%20world" target="_blank">Download me</a> 

    • Attention , for data-uri, they write that the old Edge will fall, but I brought it here as an easy way to show how it will work.
    • This attribute is subject to the same-origin policy.
    • target = "_blank" will work for browsers that do not support download, new browsers should not open a new tab, if there is a download

    Another option is to change the mime-type on the server side, then the browser will not attempt to render the file at all and target="_blank" will not be needed.

    a couple of examples

    • I have a browser and so it does not render the files, there’s not the point, it’s downloading all the files, it doesn’t open. target = "_ blank" is in case the link stops working, or the program stops running, so that the current page with prompts is open. - Goooooo
    • I still want to understand how target = "_ blank" works in Edge in the second example - Goooooo
    • in the first example, the link to the page that ultimately makes location.replace via js, in the second example, the link to the file itself. - zb '
    • I don’t understand what target="_blank" helps you with, unless it’s strange to hang analytics counters. if you make a "download" then there will be no transition, even if it is 404. - zb '
    • Some programs block antiviruses, for example, CCleaner considered Nod32 antivirus to be undesirable several weeks ago (maybe even now, it did not check). When I tried to download it, a window with a NOD32 message about blocking opened - I think it’s better to open such windows in a new tab, so I’m ticking all links to target = "_ blank" by default. - Goooooo