How to upload an image using image url from web in javascript or jquery?

882 Views Asked by At

I have a page , I need to Add a Picture from the web using it's URL and display it in my page same as the below image using Jquery or Javascript.

enter image description here

2

There are 2 best solutions below

0
On

You need to have a textbox where you can enter the url for the image and a button to attach an event.

var button = document.getElementById("button"),
    input = document.getElementById("input"),
    image = document.getElementById("image"),
    src;

// button click event
button.onclick = function(){
  // in case you want to use somewhere else
  src = input.value;

  // set the image src to the input value
  image.src = src;
}
<input id="input" type="text"/>
<button id="button">click me</button>
<img id="image" height="200px"/>

0
On
  • It just updates the image 'src' attibute and shows the image. and which is not saved ,and its not performing like input type ='file'.