There are pictures, after clicking on the picture, the code is executed:
var isAdmin = confirm("Скачать"); How to make sure that when true returns true download of the image that was clicked begins?
There are pictures, after clicking on the picture, the code is executed:
var isAdmin = confirm("Скачать"); How to make sure that when true returns true download of the image that was clicked begins?
To allow the user to upload an image or other file you can use the HTML5
downloadattribute.
You can emulate this download.
function saveUrlAsFile(url, fileName) { var link = document.createElement("a"); link.setAttribute("href", url); link.setAttribute("download", fileName); link.click(); } $('img').on('click',function(e){ var isAdmin = confirm("Скачать?"); if(isAdmin){ saveUrlAsFile($(e.target).attr('src'), 'image.jpg'); } }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <img width="100" src="https://pbs.twimg.com/profile_images/378800000567859274/3d56eadbc1e389780a95c74189ebfa64.jpeg" /> <img width="100" src="https://shkolazhizni.ru/img/content/i133/133607_or.jpg" /> $('img').on('click',function(e){ var isAdmin = confirm("Скачать"); if(isAdmin){ document.location.href = $(e.target).attr('src'); } }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <img width="100" src="https://pbs.twimg.com/profile_images/378800000567859274/3d56eadbc1e389780a95c74189ebfa64.jpeg" /> <img width="100" src="https://shkolazhizni.ru/img/content/i133/133607_or.jpg" /> And then the magic from the server side (For example, PHP):
header('Content-Disposition: attachment; filename="123.jpg"'); Content-Disposition: attachment; This can be done both in the back-end and in the web server settings. - MaximSource: https://ru.stackoverflow.com/questions/731647/
All Articles