Jump to content

How to include html,css, javascrip in TUnimHTMLFrame


asapltda

Recommended Posts

8 hours ago, asapltda said:

I want to include the attached files in the component. Can someone help me?

Hello,

For example:

1. Copy the files (script.js, styles.css) to the files directory.

2. UnimHTMLFrame.HTML ->

<!DOCTYPE html>
<html>
<head>
  <title>Imprimir Texto</title>
  <script src="files/script.js"></script>
  <link rel="stylesheet" href="files/styles.css">
</head>
<style>
    .container {
    text-align: center;
    margin-top: 50px;
  }
  
  #textToPrint {
    font-size: 18px;
    margin-top: 20px;
    border: 1px solid #000;
    padding: 10px;
  }
</style>
<body>

<div class="container">
  <button id="printButton">Imprimir Texto</button>
  <div id="textToPrint">Este es el texto que se imprimirá.</div>
</div>

<!--<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>-->

</body>
</html>

<script>
    $(document).ready(function(){
    $('#printButton').on('click', function(){
      var text = $('#textToPrint').text();
      printText(text);
    });
  });
  
  function printText(text) {
    var printWindow = window.open('', '_blank');
    printWindow.document.write('<html><head><title>Texto a Imprimir</title></head><body>');
    printWindow.document.write('<h1>' + text + '</h1>');
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    printWindow.print();
  }
</script>

By the way, I commented out the line:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

 

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...