0

I want to Download an HTML file on click of anchor tag on another html.

Example: 1. I have index.html page with the anchor tag (Download Link).

  1. I have another html file (download.html).

  2. Now i want to download (download.html) file on anchor link click.

i tried using the HTML5 download attribute. but its as we know it not support to IE,safari, and opera browsers.

is their anyway to do this using Javascript ??

kishor
  • 21
  • 1
  • 2

3 Answers3

1

Without some PHP coding stuff it is not possible directly to download a Text file with HTML enter code here. You have to compress and ZIP that file, and than provide the link in HTML.

<a href="myfile.zip" target="_blank">Download</a>

And also if you decide to use that PHP stuff, read this question.

For doing it to JS read this question.

Community
  • 1
  • 1
Romo Daneghyan
  • 2,099
  • 3
  • 18
  • 23
0

You can use window.location.href in javascript

<a href="#" target="_blank">Download this</a>

then js code just prevent the link from redirecting.

$('a').click(function(e){
                e.preventDefault();
                window.location.href = 'http://practice.com/materialize.rar';
});
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
-2

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

Download

dastar
  • 1