Home > Web Front-end > HTML Tutorial > html realizes click to download files directly

html realizes click to download files directly

王林
Release: 2020-03-03 17:58:43
forward
11387 people have browsed it

html realizes click to download files directly

1. Use the tag

so that when the user opens the browser and clicks the link, the file will be downloaded directly.

But there is a situation, such as txt, png, jpg and other files that the browser supports direct opening will not perform the download task, but will open the file directly. At this time, you need to add an a tag Attribute "download";

(recommended learning tutorial: html introductory tutorial)

The example is as follows:

Move to the label label You can display the file path and complete the file path according to the path prompt

If you need to download from the image uploaded on the web page, you may use the following method:

Get the host domain name:

location.hostname

Get the port number:

location.port

2. Use the button to listen

Button monitoring can be divided into two methods,

The first is window.open()

The second is form submission

For more programming related content, please pay attention PHP Chinese websiteIntroduction to Programming column!

The above is the detailed content of html realizes click to download files directly. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template