I have on the client side (mobile) a timer (setTimeout()) which triggers refreshing the token on the server side by sending a post message to the server.
That timer does not seem to trigger sending a message to the server when the screen timeout on my mobile is on and the screen is black.
How can I enable triggering even if the mobile has the screen switched off.
I don't think there is a a way for angular to know when a page is locked. You could track any input or page movements instead and reset a timeout timer so that if the page stays idle for a while you could send a request to the server. That being said you would probably want the page timeout to be decently long to avoid closing a session while a user is still using the page. What you can also do is have a warning message pop up when the timeout is reached that prompts the user to say they are still using the page, if they click yes reset the timer again otherwise close the session.
Related
I want my frontend to track user inactivity (no mouse/keyboard input) and call my logout API when a specified time threshold is reached.
It seems straightforward at first (promising libraries like jquery-idletimer), however the inactivity tracking needs to support multiple tabs of the same website and even when the user closes all tabs of the website. The duration they have exited the page should count towards the threshold, and if reached while page is closed, my logout API needs to still be called. If the user reopens the page before the threshold, the timer needs to be reset.
Is this still possible from the frontend?
I use the devex time out control which is described in the following link.
DevExpress Timeout Control
It works with the session time out value which is set in web.config. Let's say if the session timeout is set to 30 minutes, then after 29 minutes, a pop up appears and shows count down from 60 and asking the user if he wants to continue his session. If the user doesn't click Okay, then the user is redirected to the login page at the end of the count down. This is the way it's supposed to work, but when sometimes I find the page being stuck, count down set to 0 and the browser tries to redirect but some how can't. I think it might have something to do browser not being in focus. Does anybody have any idea?
DevEx Timeout control uses document.location to navigate to login page when session times out. document.location doesn't work properly when browser is minimized and not having focus. Using window.location fixed the issue in IE, Chrome and Firefox.
I have a web app with some 'safety' code which causes a page reload if the server (Socket.IO) connection goes silent for more than 5 seconds (generally customer site firewall/broken-proxy issues).
The Socket.IO connection stops as soon a new page starts loading, but the safety code doesn't see this. Navigating to a slow page causes the safety code to fire and jump you back to the previous page.
I need to be able to tell (just before this code causes a reload) whether the browser is currently waiting for a new (slow) page to load.
What approaches are there to doing this, other than putting a jQuery click event on every link (which would not catch navigation via the address bar)?
Thanks,
Chris.
Monitoring window.onbeforeunload would do the trick. Fires right after the user starts navigating away.
Try typing this in the Chrome Console on any page and click on any link:
window.onbeforeunload = function () { console.log("oh noes"); }
My recommendation: fix your code so that you don't reload the page when the socket disconnects. Problem solved.
Edit
I suppose you could simply set a variable such as isReloading when the page reloads. You'd need to monitor onbeforeunload as well, and check what happens first: disconnect or the unload event. If the disconnect happens first, you're getting disconnected. Trigger the isReloading flag and reload. In the onbeforeunload check whether the flag was set. Reverse the concept of checking whether a slow page is loading: check whether you are reloading.
What would be the best way to monitor activity of a user on the page? I am developing a CMS system and using this as a security feature, if user is inactive for set amount of minutes then jQuery would trigger a function which would trigger whole page overlay and load in login script having to force the user to re-enter the password in-order to reopen the page or else after so many failed attempts PHP would force the user to logout script and destroy entire session.
So here how it would go
If no activity after 5min
jQuery(checks user activity every 5min) -> loop <- jQuery(if no activity after 5min) -> function(trigger overlay + authorization script via AJAX)
If there is activity
jQuery(checks user activity every 5min) -> loop <- jQuery(if active go back to loop)
So ye this is about it, thanks in advance.
Activity Definition for this script: Movement of mouse or input(keyboard) of text into text fields or clicking elements.
You can use jQuery's Idle Timer plugin.
As Justin says, jQuery does have an idle timer plugin. However, this method is not going to be sufficient alone unless your idle timer also destroys login cookies - your overlay can easily be circumvented by an array of browser plugins, or even (depending on how your application is built) GET parameters.
Reloading the page would even circumvent this "security" unless you log the user out.
I am working on any application in which i need to detect that whether user close the tab or browser so I can disconnect the user from other user basically its an chat application.
I have used :-
window.onbeforeunload = confirmExit;
function confirmExit() {
if(needToConfirm) {
return "Leaving this page will end your conversation.";
}
Its work fine, when I try to close the browser or tab it shows an popup with message "Press OK to continue, or Cancel to stay on the current page."
I want to perform task when user click on Ok button and if he press cancel then will stay on current page.
Please Help me :(
Thanks in advance
Ansh J
This is not possible.
You could handle the unload event and send an AJAX request there, but that might not be completely reliable.
The best solution is to send an AJAX hearbeat every x minutes, and consider the user disconnected if you stop receiving the heartbeat.
Go the other way around: when you receive the Unload event, send the server a message that informs the user is about to disconnect. The server waits for some time and then automatically disconnects.
Then, if the user click cancel and stays on the page, you send a message to the server to inform that the client is still alive.
The downside is that, if the user waits too long to click cancel, he might be disconnected.
Why not have the client's periodically 'ping' the server to let it know that they are still there, and if a user misses say 3 pings then it will be marked as logged off?