1 function downloadfile(url) {
2 var xmlHttp =
null;
3 if (window.ActiveXObject) {
4 // IE6, IE5 浏览器执行代码
5 xmlHttp =
new ActiveXObject("Microsoft.XMLHTTP"
);
6 }
else if (window.XMLHttpRequest) {
7 // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
8 xmlHttp =
new XMLHttpRequest();
9 }
10 //2.如果实例化成功,就调用open()方法:
11 if (xmlHttp !=
null) {
12 xmlHttp.open("get", url,
true);
13 xmlHttp.send();
14 xmlHttp.onreadystatechange = doResult;
//设置回调函数
15 }
16 function doResult() {
17 if (xmlHttp.readyState == 4) {
//4表示执行完成
18 if (xmlHttp.status == 200) {
//200表示执行成功
19 //引用js库:http://danml.com/js/download2.js
20 download(xmlHttp.responseText, "error.txt", "text/plain"
);
21 }
22 }
23 }
24 }
转载于:https://www.cnblogs.com/ybyi/p/9262450.html
相关资源:js打开浏览器文件下载框