新手求问,在点击文件的下载链接后,有没有办法能获取并改变另存为对话框中默认的文件名称?若能,最好附上部分代码,谢谢!

解决方案 »

  1.   

    这是坛子里->awsbamboo115写的,主要是js的execCommand<html>
    <script language="Javascript" >
    function saveFile(T,content)
    {
      var filename=document.all(T).value;
      var win=window.open('','','top=10000,left=10000');
      win.document.write(document.all(content).innerText);
      win.document.execCommand('SaveAs','',filename+".txt")
      win.close();
    }
    </script>
    <body>
    <form name="saveas" action="" method="post">
    文件名称:<input type="text" id="title_1">
    <br>
    文件内容:<textarea id="content_1">
    网站制作学习网
    </textarea>
    <br>
    <input type="button" value="save as txt file" onClick=saveFile('title_1','content_1')>
    </form>
    </body>
    </html>
      

  2.   

    要看你怎么做了。java 是有输出流的。
      

  3.   


           SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    response.setContentType("application/octet-stream");
    response.setHeader("Content-length", workbook.getBytes() + "");
    String filename = new String((sdf.format(new Date()) + ".xls")
    .getBytes("GBK"), "iso8859-1");
    response.setHeader("Content-disposition", "attachment; filename="
    + filename);
      

  4.   

    谢谢,但我所有的只是类似于http://ishare.iask.sina.com.cn/download/explain.php?fileid=62142415这样的链接,点击链接后会直接出现另存为的窗口,这时在另存为的窗口里面已经有了一个默认的文件名,是否能修改这个文件名?
      

  5.   

    <a href="http://server/site/test.txt" download="test001.txt">Download Your File</a>目前好像只有Chrome支持。
    http://stackoverflow.com/questions/7428831/javascript-rename-file-on-download
      

  6.   

        这个对于上面的链接有效,很感谢!可是对于http:xxx/uploadFile/downloadFile.jsp?module_id=xxx&filePath=xxx&file_id=xxx这样的链接好像没什么用啊?每次下载的时候都会在文件名后面带一串数字,不想每次手动删除,想写一个自动删除的脚本
      

  7.   

    谢谢,但我所有的只是类似于http://ishare.iask.sina.com.cn/download/explain.php?fileid=62142415这样的链接,点击链接后会直接出现另存为的窗口,这时在另存为的窗口里面已经有了一个默认的文件名,是否能修改这个文件名?
    网页里有个网页名称的  你写什么点击下  就以什么保存   你可以写个get参数 然后定义个数组 从里面取啊 !!!
      

  8.   

    新浪的好像是用的 jQuery   不是很熟 
    http://ishare.iask.sina.com.cn/js/savevdisk-1.1.js