How to Use HTML Container in G Web Development Software

Updated May 9, 2023

Environment

Software

  • G Web Development Software
  • LabVIEW NXG Web Module

HTML Container allows users to render dynamic content in webVI. This will be very useful for users that would like to integrate their web application project with third-party libraries because HTML Container enables the creation of custom controls and indicators at any location within the webpage, giving flexibility nearly identical to the drag-and-drop concept!

This article will demonstrate how to display content created programmatically using Javascript using HTML Container

  1. Launch G Web Development Software.
  2. In the Panel, place HTML Container from Decoration palette. 
    image.png
  3. Right-click and select Create Reference
    image.png
  4. Place Static Control Reference (HTML Container) into the Diagram, outside of the While loop.
  5. Place Obtain JavaScript Reference next to Static Control Reference (HTML Container) and connect both of them. 
    image.png
  6. Launch a text editor and save the following code as AddH1.js. This code will create a new HTML element, H1, and append it into the HTML Container. 
    (function () {
        'use strict';
    	
    	window.addElement = function(container){
    	const newElement = document.createElement("h1");
    	newElement.innerText = "Hello World!";
            container.appendChild(newElement);
    	}
    }());
  7.  Right click WebApp.gcomp and select Import files. Import the AddH1.js. 
    image.png
  8. Right click WebApp.gcomp and select New>>JavaScript Library Interface. Name it as Library.jsli
    image.png
  9. Insert the following code to HTML script and link dependencies
    <script src="AddH1.js"></script>
  10. Insert addElement as value for Javascript Global and click Add function.
  11. Add a new JavaScript Reference parameter
    1. Click Add Parameter.
    2. Highlight the newly created parameter and expand the right Item pane.
    3. In the Item pane, configure the parameter's data type to be JS Reference.
    4. Rename it as container
      image.png
  12. In index.gviweb, drag-and-drop AddElement from Project Items>>Software>>WebApp>>Library.
  13. Connect AddElement's container input with Javascript reference out from Obtain JavaScript Reference. 
    image.png
  14. It is ready to run. Observe that the "Hello World!" will be displayed at the location HTML Container is placed.

Below is the result of running it in G Web Development Software:
image.png
Below is the result of running it in browser:
image.png