[英]How can I download image which is rendered with <img> tag?
Let me explain my use case:让我解释一下我的用例:
I have a page, where I fetch the image by the url (from remote host) and display it.我有一个页面,我通过 url(从远程主机)获取图像并显示它。 Also, I have a button on the page.
另外,我在页面上有一个按钮。 When clicked, the image should be downloaded.
单击时,应下载图像。 I want to download the image without making any other remote calls.
我想下载图像而不进行任何其他远程调用。
So overall I want to support two things with a single fetch of the image:所以总的来说,我想通过一次获取图像来支持两件事:
Can you help me with how can I do that?你能帮我解决这个问题吗?
Did you see window.location.href?你看到 window.location.href 了吗? https://www.w3schools.com/js/js_window_location.asp
https://www.w3schools.com/js/js_window_location.asp
in my reference project I was taking an image from the back end, making a URL.createObjectURL (img) and assigning a function to a button that simply does window.href.location = Processedimage on on: click.在我的参考项目中,我从后端拍摄了一张图像,制作了 URL.createObjectURL (img) 并将 function 分配给一个按钮,该按钮只需执行 Z05B8C74CBD96FBF2DE4C1A352702 上的 Z05B8C74CBD96FBF2DEFBF2DE4C1A352702.hlocation。 This way you can open the original image in another browser window, but again, I don't know how useful it will be.
这样你就可以在另一个浏览器window中打开原图了,但是我不知道它会有多大用处。 it is however a possible solution
然而,这是一个可能的解决方案
There is actually no way to download the img tag directly, but you could use insert the image in an <a> element Like:实际上没有办法直接下载 img 标签,但是您可以使用将图像插入到 <a> 元素中,例如:
<img src="img_src">
<a href="img_src" download>
</a>
Is this what you mean?你是这个意思吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.