博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js下载文件
阅读量:4559 次
发布时间:2019-06-08

本文共 1523 字,大约阅读时间需要 5 分钟。

<input   type=button   value=另存为   οnclick="mm1()">   

  
  <iframe   width=0   height=0   frameborder=0   name=hrong   style="display:   none"></iframe>  
      <script language="JavaScript">
      //有窗口弹出的下载
     /* function  openfile()
       {     
           var a;
           a =window.open("下载文件的URL","_blank", "width=0, height=0,status=0"); 
           a.document.execCommand("SaveAs");     
           a.close();    
       }  */
      //无窗口弹出
      function   mm1()   
    {   
          var str="下载文件的URL";     
          window.frames["hrong"].location.href   =   str;   
          sa();   
 }   
 function   sa()   
 {   
        if(window.frames["hrong"].document.readyState!="complete")   
             setTimeout("sa()",   100);   
       else   
          window.frames["hrong"].document.execCommand('SaveAs');   
  }   
      </script>
 
我自己的需求

//上传附件

$(function () {
$('#uploadFile').uploadify({
'uploader': '/App_Themes/Default/uploadify.swf',
'script': '/OrderManage/Upload',
'folder': '/UploadFiles',
'auto': true,
'width': 160,
'height':25,
'queueID': 'fileQueue',
'sizeLimit': 1024 * 1024 * 4,
'multi': true,
'fileExt': '*.doc;*.docx;*.pdf;*.pptx;*.txt;', ///设置可选择文件的类型
'fileDesc': ' Files (.doc, .docx, .pdf , .rar)', //允许上传文件的类型
'buttonImg': '/App_Themes/Default/Province/images/upload.png',
'onComplete': fun2
});

})

 下载附件

//无窗口弹出

function mm1() {
var filename = $("#result2").text();
///UploadFiles/2013-12-31-16-44-9.docx
var str = "../../UploadFiles/"+filename; //文件的url
window.frames["hrong"].location.href = str;
// sa();
}
// function sa() {
// if (window.frames["hrong"].document.readyState != "complete")
// setTimeout("sa()", 100);
// else
// window.frames["hrong"].document.execCommand('SaveAs');
// }

转载于:https://www.cnblogs.com/Danny-yang/p/3510394.html

你可能感兴趣的文章
CSS3 & Grid Layout All In One
查看>>
《机器学习实战》学习笔记第四章 —— 朴素贝叶斯法
查看>>
承接上篇scanf函数何时取&问题
查看>>
python笔记 - day4-之装饰器
查看>>
HttpWebResponse远程服务器返回错误: (500) 内部服务器错误
查看>>
关于.net MVC5+EF6 网站部署的问题
查看>>
异常 : identifier of an instance of com.mi.domain.Department was altered from 2 to 1
查看>>
实现托管代码调用非托管代码以及非托管代码调用托管代码->COM Interop
查看>>
简易乘方算法
查看>>
leetcode - Unique Paths
查看>>
舵机控制
查看>>
句柄类与继承
查看>>
cocos2d-x-3.1 事件分发机制 (coco2d-x 学习笔记七)
查看>>
多项式问题
查看>>
服务器实现的多种方法汇总
查看>>
理解jquery的$.extend()、$.fn和$.fn.extend()
查看>>
在线安装eclipse中html/jsp/xml editor插件 eclipseeditor
查看>>
MAC下彻底解决mysql无法插入和显示中文
查看>>
HDU 4456 Crowd
查看>>
Union和union all区别?
查看>>