LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect Browser close in NXG Web module

Solved!
Go to solution

I have an NXG (3.1.1) web module gviweb VI. It communicates with another VI via Systemlink tags.  Is there a way to detect when the user of the deployed webpage (created from the gviweb) closed the browser tab with this web module?  My thought was that I'd like to keep my systemlink tags open when the user is using the webpage and then close the systemlink tag references when the user closes the webpage.  I would also like to be able send a final systemlink tag to my other VI saying that a browser window has been closed.  I think this situation would be analogous to detecting a panel close in regular VI.

0 Kudos
Message 1 of 3
(2,190 Views)
Solution
Accepted by topic author pulidotech

Interesting question.  From how you have worded things, it sounds like you will only have a single user on at a time?  Depending on if you only need to detect if a single user has the webVI open on the browser or not (single instance of the webVI launched), or if you need to detect the closing of each tab/window, you have a few options.

 

Since you are using Systemlink tags, you could check the timestamps of your tags (http://www.ni.com/documentation/en/systemlink/latest/systemlink-node-ref/read-tag-timestamp/) written to from the webVI to see if they are updating.  If they are updating, it means that at least one instance of the webVI is open.  If you want to implement more of a heart-beat between the server and the webVI, you could have the webVI read a server timestamp from a tag, then write that same timestamp back to a tag that the server will read.

 

I don't believe there is an equivalent to a panel close event filter in webVIs.  If you need to detect each time an instance of the webVI is being closed, the only way I can think of accomplishing that is via JavaScript.  Here is a page on how you can detect tab/browser close events in js https://www.geeksforgeeks.org/how-to-detect-browser-or-tab-closing-in-javascript/ .  You can use that in conjunction with JSLI in LabVIEW NXG to add that functionality to your webVI.  Then, you can have your js return some value when a window close even is detected.  I think this route is only necessary if you are trying to detect each close event and would not be necessary if you just need to know if there are still open connections or not.

If you ever need to integrate js into a webVI, I highly recommend looking at some examples in github such as https://github.com/ni/webvi-examples/tree/master/CallJavaScriptFromAWebVI

Clemens | Technical Support Engineer | National Instruments
Message 2 of 3
(2,126 Views)

Thank you for the response.  I like both solutions.  I think I'll look at your heartbeat idea in the short term, and the javascript implementation is interesting for the long term.  

0 Kudos
Message 3 of 3
(2,110 Views)