Download"; 2. Use the url to jump to the download, with the syntax "window. open(file url)"."/> Download"; 2. Use the url to jump to the download, with the syntax "window. open(file url)".">
Home > Article > Web Front-end > How to implement downloading in javascript
Javascript method to implement downloading: 1. Use the href attribute of the a tag to add the file URL, with the syntax "08334b6a1e96957a52fab23a7ec52b14Download5db79b134e9f6b82c0b36e0489ee08ed"; 2. Use URL jumps to download, the syntax is "window.open(file url)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer
JS
to achieve downloading File function? The common method is to create a new download:
1. a tag
<a href="前端框架-Minton.rar">下载</a>Download other files
function commDownload1(url, params) { url += "?"; for(let key in params) { url += key + "=" + params[key] + "&"; } url = url.substr(0, url.length - 1); $("<a href=" + url + " />")[0].click(); }
2. URL jump
function commDownload2(url, params) { url += "?"; for(let key in params) { url += key + "=" + params[key] + "&"; } url = url.substr(0, url.length - 1); window.open(url);Among them, the
a tag has a better experience. The other two will open a new tag and download again. The whole process of closing the new tab feels dizzying, so it is recommended to use the
a tag to implement the download function.
The above is the detailed content of How to implement downloading in javascript. For more information, please follow other related articles on the PHP Chinese website!