js下载文件(而不是打开预览)
<html> <head> <title></title> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script> <script> function downloadByUrl() { var oReq = new XMLHttpRequest(); var URLToXML = "http://xxxxx.com/lin2kDownload/PB8hQEP5Sike7803IIz9JRYizjmh3bs1cikq6HOBSuUvC_jRUPg1Y2uS2mZnr7Ah_9T0jfkBiANdcv5Ek1W3B9iqHoQ2.xml"; oReq.open("GET", URLToXML, true); oReq.responseType = "blob"; oReq.onload = function () { var file = new Blob([oReq.response], { type: 'application/xml' }); saveAs(file, "电子发票.xml"); }; oReq.send(); } </script> </head> <body> <input type="button" onclick="downloadByUrl()" value="XML下载" /> </body> </html>
吾乃代码搬运工,侵联删