Obtain the necessary data from a URL to display the web content [duplicated]

-1

For the use of a forum, I would like to know how it could, introducing only the URL of a gif for example ( link ), obtain the necessary data so that the gif is displayed and not have to be imbibed manually.

Is information parsed with JavaScript?

    
asked by JetLagFox 08.07.2017 в 07:28
source

1 answer

0

The way to obtain the data will vary depending on the source of the data, but in any case to show an image in a web browser what is required is the URL of the image and HTML, specifically the tag img . With client-side code (web browser) JavaScript can be used to modify the element and its attributes and CSS for presentation.

Simple example using only HTML:

The next line

<img src="https://www.importancia.org/wp-content/uploads/Planeta-Tierra.jpg">

On this site, putting the previous line without code format gives the following result:

It is possible to include other attributes, for example to specify the size. All the details in img .

To modify the src attribute using JavaScript, you could use something like the following:

function agregaImagen(){
  var img = document.querySelector('img');
  img.src = "https://www.importancia.org/wp-content/uploads/Planeta-Tierra.jpg";
  img.height = "100";
}
<input type="button" value="Agregar imagen" onclick="agregaImagen();"/>
<br/>
<img>
    
answered by 08.07.2017 в 16:48