Table Of Contents

Integrating a JavaScript File Into a Web Application

Last Modified: October 2, 2018

Connect a JavaScript file to your web application and call functions you defined in a JavaScript Library Interface (JSLI) in your web application.

Before you begin, create and configure a JSLI.

  1. Import the JavaScript file(s) you want to use into your web application.
    1. Save your project.
    2. On the Project Files tab, right-click the web application document (.gcomp) and select Import files.
    3. Navigate to the JavaScript file(s) you want to add and click Open. Click Copy to close the Copy existing file(s) dialog box.
      spd-note-note
      Note  

      NI recommends you place your JavaScript file in the web application document rather than a library document. To reference a JavaScript file in the HTML panel, the file must be in the same web application document as your top-level WebVI.

  2. Integrate the JavaScript file into your web application.
    1. For each top-level WebVI that calls functions from the JavaScript file, switch to the HTML view and enter the relative path to your JavaScript file between the <head></head> tags and outside of a read only section. Example:
      <head>
      ...
            /*End read only section. ...*/
            ...
            <script src="library.js"></script>
      </head>

    2. Click Apply Changes. If you do not click Apply Changes, your changes will not take effect, and you may lose the changes you made to the HTML.
  3. Add the entry points you defined in the JSLI to any web application in your project.
    1. Open the WebVI in which you want to call the JavaScript function.
    2. On the diagram palette, click Project Items»Software»YourWebAppName. Click the Library folder to show each entry point you defined in that JSLI.
    3. Drop the entry points you want to use on the diagram.
    4. Wire the entry points and complete the diagram.
    5. Run the WebVI. Input data passes from the diagram to the JavaScript code, and output data returns from the JavaScript code to the diagram.

Recently Viewed Topics