
It still displayed a popup warning in some browsers (perhaps they got a little stricter by 2021).Īdding the pdf mime type to the href attribute solved the browser popup warning, but it messed up the file (the downloaded file got damaged and couldn't be opened). I've had some issues with the suggested solution that creates an a DOM element, and sets the download attribute. On chrome it will work without appending and removing child (window.URL || window.webkitURL).revokeObjectURL(save.href) įor new Chrome update some time event is not working.įor that following code will be use var path= "your file path will be here" Īppending child and removing child is useful for Firefox, Internet explorer browser only.


Var event = document.createEvent('Event') When you want to direct download any image or pdf file from browser instead on opening it in new tab then in javascript you should set value to download attribute of create dynamic link var path= "your file path will be here"
