How to load image from javascript using base64?

1

Good evening, I'm using this plugin: link

Here's JSFIDDLE: link

Follow the code:

HTML:

<button type="button" class="btn btn-primary">Abrir imagem</button>

JS:

$("button[class='btn btn-primary']").click(function(e) {
var imagem = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAM ... etc'
event.preventDefault();
  $(this).ekkoLightbox({
  //Como carregar imagem a partir daqui
  });
});

Is it possible to load image from javascript?

    
asked by anonymous 20.02.2017 / 04:24

1 answer

1

With jQuery, you can change the source of the image using attr or prop :

var imagem = 'data:image/jpeg;base64,/9j/...';
$("algum_seletor").attr('src', imagem);

With this you can apply some logic in ekkoLightbox .

JSFiddle: link

    
20.02.2017 / 12:28