zoukankan      html  css  js  c++  java
  • 利用 iframe 实现文件 下载

    javascript里面      

    <script type="text/javascript">

           var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_initializeRequest(downloadfile);
            //触发函数
            function downloadfile(filepath) {
                var iframe = document.createElement("iframe");
                iframe.src = "GenerateFile.aspx?filepath=" + filepath;
                iframe.style.display = "none";
                document.body.appendChild(iframe);
            }
        </script>

          <body>

        <a onclick="downloadfile('filepath') download</a>

      </body>

        public partial class GenerateFile : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string fileResponse="file content";
                string filepath = Request.QueryString["filepath"];
                Response.AddHeader("Content-disposition", "attachment; filename=report.csv");
                Response.ContentType = "application/octet-stream";
                Response.Write(fileResponse);
                Response.End();

            }
        }

  • 相关阅读:
    window.history 和 DWZ 框架
    Ztree 随笔记
    eval的对于验证数学公式的用处
    lodop打印控件一点记录
    font和lineheight冲突。
    Windows CMD命令大全
    centos 下安装pip pip3
    Linux访问windows共享文件夹
    数据库主从和读写分离的配置和使用方法
    centos7 nginx+php7yum安装
  • 原文地址:https://www.cnblogs.com/doosmile/p/2670756.html
Copyright © 2011-2022 走看看