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

            }
        }

  • 相关阅读:
    C# learn note
    深入研究Servlet线程安全性问题
    SQL Server中的临时表和表变量
    jQuery笔记
    使用ScriptX控件进行Web打印
    asp.net MVC 设置页面否编译
    Javascript闭包【转载】
    几种开源协议
    扩展IIS7支持的文件类型(转)
    VS2012关闭烦人的文件预览选项卡
  • 原文地址:https://www.cnblogs.com/doosmile/p/2670756.html
Copyright © 2011-2022 走看看