I have partially achieved to monitor if a user has left the WebApp's URL by adding into all of the WebApp's Index.html files, a hidden div element in the body section with a custom id and textcontent as such:
<div style="display: none;" id="familymember">familymember</div>
I then use a custom subroutine to read the textcontent of the hidden div element and if I get the "expected" string ('familymember' in my case), I know that the displayed page of the browser belongs to my WebApp, otherwise the user has navigated beyond the App's URLs and as of that I can proceed with the session invalidate procedure,
to force user re-login.
Monitoring Routine:
Public Sub CheckIfIsFamily(mWS As WebSocket) As String
Dim resURL As Future
Dim result As String
Try
resURL = mWS.EvalWithResult("return document.getElementById('familymember').textContent", Null)
result = resURL.Value
Catch
result = "NotFamily"
End Try
Return result
End Sub
I call the CheckIfIsFamily routine from within a Timer_Tick Event or a Client_Unload Event as follows:
If CheckIfIsFamily(WS).ToLowerCase.Trim <> "familymember" Then
Try
If InvalidateSession(WS, False) = True Then
Log("Good-Bye")
myTimer.Initialize("myTimer", 0)
myTimer.Enabled = False
End If
Catch
Log(LastException.Message)
End Try
Else
Log("Family Member")
End If
So far while the application is in the ws main Index.html this approach works fine if the user
navigates away by the browsers HOME or Back Buttons, but if he navigates further
down into the WebApps module (other Index.html) I get in the log, a flip-flop effect
as such:
"NotFamily" and on the next Timer tick "Family Member" and so on.
I was wondering if this problem has to do with the WebSocket been passed as parameter
to the next module and not interpreted correctly.
By the way I would like to thank everyone for their help.
Regards
Chris