Archived:Redirect Webpage Programmatically in LabVIEW NXG Web Module

Updated May 1, 2023

NI does not actively maintain this document.

This content provides support for older products and technology, so you may notice outdated links or obsolete information about operating systems or other relevant products.

Environment

Software

  • LabVIEW NXG Web Module
  • LabVIEW NXG

To date, there is only one approach available in LabVIEW NXG Web Module to automate the webpage redirection. This article will share with you how to accomplish this feature with example.

Webpage redirection can be accomplished by having LabVIEW NXG calling JavaScript functions using a JavaScript Library Interface (JSLI). Kindly refer to the instructions below to build a working example of it.
  1. Select Projects>>Web Application Project in the main menu of LabVIEW NXG. create project
  2. Click Create after you have name your Web Application Project accordingly. create
  3. Save your project at a desired location. You are not able to import files if you did not save your project. save
  4. Open a text editor and have the following Javascript function save within it. For this example purpose, let's name the file as url.js .
    (function () {
        'use strict';
    
        window.setWindowLocation = function (url) {
            window.location.href = url;
        };
    
    }());
  5. Right-click WebApp.gcomp and select Import files to import the url.js into this web application project. import url.js
  6. Create a JavaScript Library Interface (JSLI) by selecting New>>JavaScript Library Interface. create jsli
  7. A new Library.jsli tab will be opened. You should fill in the details as below. config jsli
    • In the HTML script and link dependencies section, you should replace url.js if your JavaScript function is saved with another name.
    • setWindowLocation should be filled in JavaScript Global because setWindowLocation is the name of the JavaScript function in our url.js.
  8. Click Add function.
  9. Collapse the side panel. collapse
  10. Due to our JavaScript function requires one argument, click Add parameter to add an additional argument. add parameter
  11. Expand the side panel and change the argument type to String. You can also rename the argument to suit your function. In the image below, the argument has been renamed as url as the function is expecting the user to provide a url for redirection. type
  12. Drag and drop the following Code Snippet into index.gviweb's Diagram. snippet​​

    • Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
    • The setWindowLocation function can be found by using the Search feature or press <Ctrl-Space>.
  13. Select Run in Browser. A new tab will be open in your default browser. What you can see is after 5 seconds, the tab will automatically navigate to www.ni.com. navigate