Download a zip file using JS window.open _self without a "useless window"

The following information is from this page that discusses the “useless empty window” problem, while trying to create a script that starts the zip file download:

<script>window.open('archive.zip','_self')</script>

The above download loads correctly, but the page is full, the content is not displayed. I see that the whole source is loaded, but not displayed.

How can I use js to start asynchronous downloads when loading page content without a "useless window"?

0
source share
1 answer

iframe. Window.open _self.

<a href="archive.zip" target="download_frame">Initiate download from link</a>
<iframe id="download_frame" name="download_frame" src="about:Blank" style="width:0px; height:0px; overflow:hidden;" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript">
    // initiate download by script
    // add this in onload event or after the iframe
    document.getElementById('download_frame').src="archive.zip";
</script>
+2

Source: https://habr.com/ru/post/1618464/


All Articles