toBase64.html 510 B

123456789101112131415161718192021
  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <script src="../dist/JsBarcode.all.js"></script>
  7. <script>
  8. function textToBase64Barcode(text){
  9. var canvas = document.createElement("canvas");
  10. JsBarcode(canvas, text, {format: "CODE39"});
  11. return canvas.toDataURL("image/png");
  12. }
  13. </script>
  14. </head>
  15. <body>
  16. <a id="hello">Click Here</a>
  17. <script>
  18. document.querySelector("#hello").href = textToBase64Barcode("HELLO");
  19. </script>
  20. </body>
  21. </html>