[英]Download HTML file on anchor tag click
I want to Download an HTML file on click of anchor tag on another html. 我想点击另一个HTML上的锚标记来下载HTML文件。
Example: 1. I have index.html page with the anchor tag (Download Link). 示例:1.我有带有锚标记的index.html页面(下载链接)。
I have another html file (download.html). 我还有另一个HTML文件(download.html)。
Now i want to download (download.html) file on anchor link click. 现在,我要在锚链接单击上下载(download.html)文件。
i tried using the HTML5 download attribute. 我尝试使用HTML5下载属性。 but its as we know it not support to IE,safari, and opera browsers. 但据我们所知,它不支持IE,Safari和Opera浏览器。
is their anyway to do this using Javascript ?? 反正他们使用Java来做到这一点?
Without some PHP
coding stuff it is not possible directly to download a Text file with HTML enter code here
. 没有一些PHP
编码的东西,就不可能enter code here
直接下载带有HTML enter code here
的文本文件。 You have to compress and ZIP
that file, and than provide the link in HTML
. 您必须压缩并ZIP
该文件,然后提供HTML
的链接。
<a href="myfile.zip" target="_blank">Download</a>
And also if you decide to use that PHP
stuff, read this question. 而且,如果您决定使用该PHP
东西,请阅读此问题。
You can use window.location.href
in javascript 您可以在javascript中使用window.location.href
<a href="#" target="_blank">Download this</a>
then js code just prevent the link from redirecting. 然后js代码只会阻止链接重定向。
$('a').click(function(e){
e.preventDefault();
window.location.href = 'http://practice.com/materialize.rar';
});
To download a file by using anchor tag use following method: Download 要使用定位标记下载文件,请使用以下方法:下载
file path is a path were your file is store after uploading.. suppose you create a folder name "File" in your site folder in which you store a file name adc.doc to download this file use 文件路径是上载文件后存储的路径。假设您在站点文件夹中创建一个文件夹名称“ File”,在其中存储文件名adc.doc以下载此文件
Download 下载
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.