如何从其他网站下载html文件 [英] How to download html file from another website
问题描述
我想从其他网站下载一个html文件,我尝试了以下代码,但它无效,它只是重定向到网站:
I want to download an html file from another website , I have tried the following code but it's not working , It just redirects to the website:
<a href='http://example.com' download>Download</a>
那么如何从其他网站下载html文件?
So how to download an html file from another website?
推荐答案
< a>
用于将用户定向到指定的链接。在html5中,您可以添加属性 download
并链接到特定文件,以表示您打算以下载方式提供该文件。
The <a>
is for directing a user to a specified link. In html5 you may add the property download
and link to a specific file to signify that you are intending to serve the file as a download.
在这种情况下,href值应指向特定文件而不仅仅是目录。带有链接的html文件还必须在顶部<!DOCTYPE html>
中标记为html5的doctype。
In this case the href value should point to a specific file and not just a directory. The html file with the link must also be marked with a doctype for html5 at the top <!DOCTYPE html>
.
您必须从与您的网站相同的域提供html /下载,或者处理CORS这是另一个主题。
You must serve the html/download from the same domain as your site or else deal with CORS which is another topic.
示例
<a href='http://example.com/myFileToDownload.html' download>Download Source</a>
这篇关于如何从其他网站下载html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!