search
HomeWeb Front-endJS TutorialJS download file | no refresh download file sample code_javascript skills

Backend code Handler.ashx

Copy code The code is as follows:



using System;
using System.Web;

public class Handler: IHttpHandler {

public void ProcessRequest ( HttpContext context) {
string fileName = "web.config";//The file name saved by the client
string filePath = context.Server.MapPath("web.config");//Path
/ /Download files as character streams
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
byte[] bytes = new byte[(int) fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
context.Response.ContentType = "application/octet-stream";
//Notify the browser to download the file instead of opening it
context.Response.AddHeader("Content-Disposition", "attachment; filename=" HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();
context.Response.End();
}

public bool IsReusable {
get {
return false;
}
}

}

Front-end code:
Copy code The code is as follows:








<script> <BR>function download_file(url) <BR>{ <br><br>if (typeof (download_file.iframe) == "undefined") <BR>{ <BR>var iframe = document .createElement("iframe"); <BR>download_file.iframe = iframe; <BR>document.body.appendChild(download_file.iframe); <BR>} <BR>// alert(download_file.iframe); <BR> download_file.iframe.src = url; <br><br>download_file.iframe.style.display = "none"; <br><br><br><br>} <BR></script>


aaaaa
bbbbb
ccccc


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
vivo浏览器下载的文件在哪vivo浏览器下载的文件在哪Feb 23, 2024 pm 08:55 PM

vivo浏览器下载的文件在哪?vivo浏览器中下载的文件是会储存在专属的位置,但是多数的小伙伴不知道vivo浏览器下载文件的位置在哪里,接下来就是小编为用户带来的vivo浏览器下载文件打开方法图文教程,感兴趣的用户快来一起看看吧!vivo手机使用教程vivo浏览器下载的文件在哪1、首先打开浏览器APP,然后进入到浏览器主界面最底部点击【菜单】;2、之后下方展开功能栏,点击【下载记录】选项;3、接着在下载记录的界面,选择【下载完成】字样;4、选择你需要查看下载文件的位置,点击后方的【打开】按钮;5

迅雷ed2k怎么下载文件?迅雷ed2k使用方法教程迅雷ed2k怎么下载文件?迅雷ed2k使用方法教程Mar 14, 2024 am 10:50 AM

  迅雷ed2k怎么下载文件?ed2k作为一种常见的共享文件,很多的用户们在下载的时候会遇到不支持下载的情况发生,那么迅雷要怎么下载?下面就让本站来为用户们来介绍一下迅雷ed2k使用方法教程吧。  迅雷ed2k使用方法教程  1、复制ed2k链接。  2、打开“迅雷”点击左上角“+”。  3、复制链接点击“立即下载”即可。

苹果手机qq下载的文件在哪苹果手机qq下载的文件在哪Mar 08, 2024 pm 02:50 PM

QQ作为一款广受欢迎的即时通讯软件,几乎每个人都拥有一个QQ号码。使用苹果手机时,可能会遇到文件存储和查找的困难。一般来说,这些文件存储在对应应用程序目录下的Documents文件夹中。苹果手机qq下载的文件在哪1、首先打开iPhone手机上的QQ应用,点击个人头像进入个人页面。2、在个人页面下方的菜单中,选择【我的文件】并点击打开。3、然后进入【本机文件】,查看手机上QQ保存的文件。4、在本机文件中,点击查看按钮即可查看下载的文件信息。

小红车创意工坊下载的文件在哪小红车创意工坊下载的文件在哪Mar 20, 2024 am 09:47 AM

用户可以使用小红车创意工坊下载各种壁纸,有很多用户不知道小红车创意工坊下载的文件在哪,用户可以在content下找到找到带数字的文件夹,下载的文件都在这里。小红车创意工坊下载的文件在哪答:在本地文件夹-steamapps-workshop-content里。1、打开steam,找到WallpaperEngine:壁纸引擎。2、右键点击管理,再点击浏览本地文件。3、打开文件夹,点击steamapps。4、点击workshop。5、点击content。6、找到带数字的文件夹。7、所有下载好的壁纸都在

如何在Windows 11系统中设置下载文件的保存磁盘如何在Windows 11系统中设置下载文件的保存磁盘Apr 20, 2024 pm 06:32 PM

对于初次接触Windows11系统的用户而言,通常文件下载路径会遵循系统默认设定,往往将文件保存在系统盘内,长期下来可能会因占用过多系统盘空间而影响电脑的整体性能。为了更合理地管理和分配存储空间,学会如何在Windows11系统中自定义下载文件的保存磁盘至关重要。本文将详细解读在Windows11中如何灵活设置下载文件的目标磁盘,以满足用户个性化的存储需求。如果您正有此需求,不妨继续阅读,我们将为您详细介绍这一实用功能的操作步骤。操作方法1、双击打开桌面上的"此电脑"。2、接着找到新界面左侧栏中

在PHP中通过AJAX调用下载文件在PHP中通过AJAX调用下载文件Sep 05, 2023 am 11:33 AM

使用Ajax下载文件被认为不是一个好主意。相反,应使用window.location=或document.location。'window.location'具有以下特点-需要启用JavaScript不需要PHP。它有助于显示内容网站,并在几秒钟后重定向用户。重定向可以取决于任何条件,例如-$success=1if($success){&nbsp;&nbsp;window.location.href=&#39;http://example.com&#39;;}名为

解决火狐浏览器下载文件失败的方法解决火狐浏览器下载文件失败的方法Jan 29, 2024 pm 08:12 PM

火狐浏览器下载文件失败怎么办?各位在使用火狐浏览器进行文件下载的时候,是否遇到过文件下载失败的情况呢?导致出现这个问题的原因非常多,系统设置不当,文件内容错误,下载链接报毒等都有可能导致这个问题,不过大多数时候都是系统设置不当导致的无法正常下载,那么这时要怎么恢复正常呢?下面就由小编为大家带来火狐浏览器下载文件失败解决方法。火狐浏览器下载文件失败解决方法1.在电脑上打开火狐浏览器并进入首页,2.点击箭头位置亲此追进入下拉菜单并点击选项,3.在选项页面的左侧,我们找到菜单,4.点击隐私与安全,5.

钉钉下载文件怎样查看地址_钉钉下载文件查看地址介绍钉钉下载文件怎样查看地址_钉钉下载文件查看地址介绍Mar 29, 2024 pm 07:16 PM

1、打开钉钉,点击文件小助手。2、点击一个文件进入。3、点击左下角的下载。4、可以看到文件存储的详细位置。5、打开文件管理,在手机存储里搜索DingTalk即可看到下载的文件了。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),