var hrefvalue = "Data:application/vnd.ms-excel;base64," + wbout;
anchor.download = filename + '. txt '; Format random
anchor.href = hrefvalue;
Server-Side
The new feature of HTML5 adds a download attribute to the a tag, fill in the filename in the download attribute, and href fills in the address you want to jump (jump page download page, jump file download file, such as you are a little PDF directly open, now you can download a little), You can download the corresponding file so that when you click on the link, the browser does not open the link to the file, but instead download (currently only Chrome, Firefox and opera support).
<a href= "Www.xxx.com/document/a.txt" download= "Newname.txt" >
Browser End
Method One, Datauri, more common is the picture of SRC, such as:
explain Datauri:
First, the URL is not just a common kind, there are also used to transmit data,
The example above contains the following sections:
Data-contract name to obtain
Image/png-Data type name
Base64-coding method of data
R0lgoxxxxx ...-encoded data
: , ; -separator symbol specified by data URI scheme
It means to transmit an IMG file encoded in base64 what is base64
Simply put, it translates some 8-bit data into standard ASCII characters, and JS and PHP can be base64 processed
Citation: http://www.alloyteam.com/2014/01/use-js-file-download/
function DownloadFile (fileName, content) {
var aLink = document.createelement (' a ');
var blob = new blob ([content]);
var evt = document.createevent ("htmlevents");
Evt.initevent ("Click", False, False)//initevent without the latter two parameters in FF will be an error, thanks to Barret Lee's feedback
alink.download = fileName;
Alink.href = Url.createobjecturl (BLOB);
Alink.dispatchevent (EVT);
}