I have multiple links that are generated to allow customers to download files. All links are something like:
<a href="http://example.com/index.php?main_page=download&order=3&id=5" class="downloadLink">File 1</a>
<a href="http://example.com/index.php?main_page=download&order=3&id=6" class="downloadLink">File 2</a>
<a href="http://example.com/index.php?main_page=download&order=3&id=7" class="downloadLink">File 3</a>
I would like to start the download automatically when the page loads (show the "save as" popup or download directly).
Is there a simple way of doing this with jQuery? I managed to come up with this code
$(document).ready(function() {
$( ".downloadLink" ).each(function() {
var a_href = '';
$( this ).on( "click", function() {
var a_href = $(this).attr('href');
window.location.href = a_href;
alert(a_href);
});
$( this ).trigger('click');
});
});
, but it doesn't seem to work - only the latest link shows the "save as" popup. However, ALL 3 alerts are shown. What am I doing wrong?
Thanks!
window.location.href, which changes the address of the browser. There is only one href of the window. To have multiple streams, you'd have to perform via another way, like with AJAX