1
I’m using the code window.open(url, '_blank');
in javascript to download files, it downloads all type automatically, but images it opens the image on a page and not download.
1
I’m using the code window.open(url, '_blank');
in javascript to download files, it downloads all type automatically, but images it opens the image on a page and not download.
0
Have an option without using JS.
Just use the HTML attribute download
on a tab <a>
which link the image. Then you put this tag <a href="link da imagem"
> involving the tag <img>
and ready. The caveat is that for this attribute to work the source and destination URL must be at the same source.
OBS: Does not work locally, only works if you are on the Server, even if you are on Xamp or Wamp.
You can mer more here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes
<a href="caminho da imagem" download>
<img src="caminho da imagem" alt="">
</a>
I tested this mode, but when I click to download, it opens the page with the image
Other files it downloads
@Pedrohenrique worked here... I don’t know if this could be some security config of the browser you use, or the server.... But it worked here, and look what I did by hand by Devtools, I didn’t even have to upload anything in FTP... You have the link site? It is likely that locally this does not work, you need to put the file in serve and test to see!
I am using Vue js webpack as frontend, and Laravel as backend, I will now test the download in the same domain
I tested with an aquivo, and it is as you had mentioned, works only if it is in the same domain
@Pedrohenrique cool that worked! Maybe with JS tb right. Sometimes appears some simpler answer.
Browser other questions tagged javascript html html5
You are not signed in. Login or sign up in order to post.
I think this link can help you: https://answall.com/questions/13826/como-for%C3%A7ar-files-type-txt-to-be-downloaded
– Vinícius