Display qrcode on an alert

-1

I have this code:

$("#exemplo1").click(function(){
  $('#codigoQrCode').qrcode(JSON.stringify('teste'));

    //se vcs clicarem aqui, aparecerá o qrcode(canvas)
 });
 
 $("#exemplo2").click(function(){
  alert($('#codigoQrCode').qrcode(JSON.stringify('teste')));

    //aqui eu gostaria de exibi-lo no alert, como vcs podem ver ele me retorna o objeto 
 });
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>

<div id="codigoQrCode"></div>
<button id="exemplo1">Clique 1</button>
<button id="exemplo2">Clique 2</button>

Is there any way to display this qrcode / canvas in an alert?

    
asked by anonymous 04.01.2019 / 18:28

1 answer

1

You can simulate an alert, I used jquery ui to create a modal to display the Qr Code, but you can also create a custom one according to your preference, see the example below:

$("#exemplo1").click(function(){
  $('#codigoQrCode').qrcode(JSON.stringify('teste'));
  $( "#dialog" ).dialog();
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script><buttonid="exemplo1">Clique 1</button>

<div id="dialog" title="Basic dialog">
  <div id="codigoQrCode"></div>
</div>
    
04.01.2019 / 18:36