html + javascript 如何实现点击下载链接或按钮弹出下载对话框
html + javascript 如何实现点击下载链接或按钮弹出下载对话框
我要下载的是 .excel .word .pdf .ppt文件
使用
<a  href = "document/ProviderRecommend.xls" >下载</a>
来做,系统总是默认打开该文件,而不是弹出下载框。
用zip文件来做时候,
<a  href = "document/ProviderRecommend.zip" >下载</a>
也是打开个窗口,在窗口中能见到该ProviderRecommend.xls文件,还是无法弹出下载对话框;
请高手指教!
------解决方案-------------------- href 应该是超链接标签
------解决方案--------------------FTP
------解决方案--------------------
我用的方法是提交到action中处理 
如下: 
        if    (action.equalsIgnoreCase("docatt"))    { 
                    //下载指定文公的附件 
                BufferedOutputStream    bos    =    null; 
                String    docid    =    request.getParameter("docid"); 
                String    filename=request.getParameter("filename"); 
                StringBuffer    sb    =    new    StringBuffer(50); 
                sb.append("attachment;    filename="); 
                sb.append(filename); 
                try    { 
                    if    (null    !=    docid    &&    filename    !=    null)    { 
                        response.setContentType("application/x-msdownload;charset=GB2312"); 
                        response.setHeader("Content-Disposition",    new    String(sb.toString() 
                                .getBytes(),    "ISO8859-1")); 
                        String    tmp    =    commonFunc.uploadpath    +    docid    +    "/"    +    filename; 
                        FileInputStream    fis    =    new    FileInputStream(tmp); 
                        bos    =    new    BufferedOutputStream(response.getOutputStream()); 
                        byte[]    buffer    =    new    byte[2048]; 
                        while    (fis.read(buffer)    !=    -1)    { 
                            bos.write(buffer); 
                        } 
                        bos.write(buffer,    0,    buffer.length); 
                        fis.close(); 
                        bos.close(); 
                    } 
                }    catch    (IOException    e)    { 
                    log.error(e); 
                } 
            } 
我也是和你一样的方法,不过我就没有空白页面,直接下载下来,你的文件不要用链接形式链接到需要的地址,而是点了链接以后产生onclick事件,然后再Javascript中提交form 
______________________________________________________________
JS方法
</SCRIPT>
   <script language=JavaScript>  
   function     savepic(){  
   if(document.all.a1==null){  
   objIframe=document.createElement("IFRAME");  
   document.body.insertBefore(objIframe);  
   objIframe.outerHTML=     "<iframe     name=a1     style='width:0;hieght:0'     src="+pic1.href+"></iframe>";  
   re=setTimeout("savepic()",1)  
   }  
   else{  
   clearTimeout(re)  
   pic     =     window.open(pic1.href,"a1")  
   pic.document.execCommand("SaveAs")  
   document.all.a1.removeNode(true)  
   }}  
   </script>  
   <a     href="<%=pic%>" id=pic1 onclick="savepic();return false;"     style="cursor:hand">
   单击下载优惠券
   </a> 
------解决方案--------------------
怎样点击直接下载
直接让客户端浏览器下载已知类型的文件
实现点击链接直接下载文件
点击后直接下载而不是将其打开
写下载链接的时候,对于txt,doc,xls等文本类型的文件,点击链接时怎样才能直接下载,而不打开呢  
如何左键点击连接连接直接下载.txt文件
网上搜到提供的方法都是用fso stream读取文件,然后通过修改http headers的办法,比较麻烦,而且效率很低。