Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
javascript: carga la biblioteca externa correctamente

Soy muy nuevo en esto. Estoy tratando de generar un código QR y mostrarlo en mi página HTMl.

Usé este código:

 /* Load the library */ <script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script> /* Basic and simple one */ <div id="qrcode"></div> <script type="text/javascript"> new QRCode(document.getElementById("qrcode"), "https://webisora.com"); </script>

Y cuando se coloca en un div, muestra un código QR como se desea.

Ahora intenté ponerlo en otro archivo desde el cual se carga todo el javascript (y ya funciona)

Así que simplemente lo puse en esta función que se llamará al cargar la página:

 function LoadQRCode() { var src = "https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js" var qrcode = new QRCode(document.getElementById("qrcode"), { text: "https://webisora.com", width: 128, height: 128, colorDark: "#5868bf", colorLight: "#ffffff", correctLevel: QRCode.CorrectLevel.H }); }

Y el div:

 <div class="qrcodecontainer"> <div id="qrcode"></div> </div>

Pero como sorpresa, la consola indica que: Uncaught ReferenceError: QRCode is not defined

Lo cual tiene sentido, ya que no sé cómo conectar la carga de la biblioteca y la carga de la variable QRCode.

Pero nuevamente, este código funciona cuando se llama directamente desde HTML.

¿CÓMO puedo alterar mi función para que también me dé el mismo resultado?

Gracias :)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Necesitas cargar un script como:

 <script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>

var src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js", esto asignará valor a var src;

Cargar script en html.

about 4 years ago · Juan Pablo Isaza Report

0

Creo que esto tendrá sentido

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js" integrity="sha512-CNgIRecGo7nphbeZ04Sc13ka07paqdeTu0WR1IM4kNcpmBAUSHSQX0FslNhTDadL4O5SAGapGt4FodqL8My0mA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> </head> <body> <div id="qrcode"></div> <script type="text/javascript"> var qrcode = new QRCode(document.getElementById("qrcode"), { text: "http://jindo.dev.naver.com/collie", width: 128, height: 128, colorDark : "red", colorLight : "white", correctLevel : QRCode.CorrectLevel.H }); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!