Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force download through js or query

Is it possible to force a download through JS or Javascript i-e the web page should not open the file in new tab in the browser but to pop up to let the user to choose eith "save as" or open with ???

like image 509
Shaun Avatar asked Sep 05 '25 16:09

Shaun


1 Answers

With the advent of HTML5 you could just use the new property download in the anchor tag.

The code will look something like

<a download="name_of_downloaded_file" href="path/to/the/download/file"> Clicking on this link will force download the file</a>

It works on firefox and chrome latest version. Should I mention that I didn't check it in IE? :P

Edited the download attribute after comment from sstur


https://caniuse.com/#feat=download

like image 193
Gokul N K Avatar answered Sep 07 '25 13:09

Gokul N K