K
K
Kusmich2015-09-15 16:20:26
JavaScript
Kusmich, 2015-09-15 16:20:26

How to implement automatic image loading?

There is a code that allows you to download an image after copying the url to the input. Tried to insert url after page load in input . But, something is not working ... Tell me how to do it right?

Here is the code:

<input placeholder="Введите урл картинки" autofocus type="text" id="myinput"/>


window.onload = function () {
 
 
    document.querySelector('input').addEventListener('input', function () {
           

        var link = document.createElement('a');

        link.href = this.value;

        link.download = 'yandex.png';

        link.click();

    }, false);
    var str = $("#myinput").val()
   var leed = "http://media.kg-portal.ru/images/shrek3/shrek3_46.jpg"
        $("#myinput").val(leed)

};


Here is the whole fiddle code: jsfiddle.net/t52ka/126

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gregory, 2015-09-15
@Kusmich

Some kind of nonsense ...
Need to upload a picture to the server from a URL? Or on a local computer?
on the computer is simple:
$('input#myinput').change(function(){
window.open($('input#myinput').val());
});
The server is more difficult, but not much ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question