<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');// }