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();

            }
        }

  • 相关阅读:
    mysql-master-ha 实现mysql master的高可用。
    一个不错的工具版本管理工具
    java的日志知识
    从解决一个java.lang.NoSuchMethodError想到的
    一个单点登录问题的解决
    关于2013年1月21日的DNS故障分析文章
    每日好的资源整理
    mongodb3.4 sharding安装文档
    python 函数
    codis3安装测试
  • 原文地址:https://www.cnblogs.com/doosmile/p/2670756.html
Copyright © 2011-2022 走看看