zoukankan      html  css  js  c++  java
  • 浏览器客户端 下载图片/文件简单处理方式

    1、如果图片头信息有

      "Content-Disposition", "attachment; filename="fileName"

      那么直接使用 iframe 设置属性src浏览器就会默认下载

      $("#iframe").attr("src",imgSrc);

    2、使用window另存为

      var fileObj=window.open(fileURL,"_blank","height=0,width=0,toolbar=no,menubar=no,scrollbars=no,resizable=on,location=no,status=no");

      fileObj.window.close();
      fileObj.document.execCommand("SaveAs");
      fileObj.close();

    3、iframe另存为方式测试为成功,待有时间再试

    注意:
    下载文件时,如果文件名存在中文,需要做url转码 URLEncoder.encode(fileName, "UTF-8") ,头信息不支持中文
    ajax不支持下载文件:https://www.cnblogs.com/nuccch/p/7151228.html

  • 相关阅读:
    前缀和
    hdu6290奢侈的旅行
    make_pair
    New Year and Buggy Bot
    STL next_permutation 算法原理和自行实现
    前端面试题集合
    node设置cookie
    黑客与geek
    xss
    node async
  • 原文地址:https://www.cnblogs.com/rgky/p/5319941.html
Copyright © 2011-2022 走看看