js file download

window.open () can only be opened once, only download a plurality of files to download 
function downloads (name, the href) {
var a = document.createElement ( "a"), to create a label //
e = document.createEvent ( "MouseEvents"); // create a mouse event object
e.initEvent ( "click", false, false); // initialize event object
a.href = href; // set Download
a.download = name; // set download file name
a.dispatchEvent (e); // to the specified elements, the event click event
}

download create multiple iframe idea of multiple files, and can not be deleted right away
sites = var [ 'URL', 'URL2'] 
for (the let I = 0; I <sites.length; I ++) {
const iframes = document.createElement ( "iframes");
iframe.style.display = "none";
= 0 iframe.style.height;
// url themselves designated
iframe.src = sites [i];
document.body.appendChild (iframe);
// iframe can not immediately be deleted, whether the person will be immediately canceled case appears
the setTimeout (() => {
iframe.remove ();
}, 3000);
}

Guess you like

Origin www.cnblogs.com/shihx/p/12467246.html