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.
Related
I have a website in which I've added a code with which it reloads every 1-2 mins.
All I want to do this is, place a timer code there, and put a go-to "X" URL script after that time is completed.
But timer and that script got refresh after page reloads?
How to prevent and at the same time implement timer and go to a URL?.
Any Ideas?
You can't refresh a page and keep it's script not refreshed, but... you can use window.localStorage or document.cookie!
I would check if the cookie exists.
If not: create a cookie, make it's value the current
Date.now().
If there is a cookie, compare it's Date to the current to get
the time passed. Then, you can redirect as wanted and delete the
cookie.
I have issue with mobile website.. which are I cant track-down, it may be from malware on user phone or maybe adnetwork.. only few visitor got this issue
when user visit my web.. they will redirect to other website mobiphone-tips or cellphone-tips and it random very few time days, normally in fist time of day only.
I'm trying looking the way to override all default redirect javascipt to return false, so keep user stay on page.. they only go as they wish when click on a links
i have tried with window.onbeforeunload place on header .. but this also stop user from click a link
Please help
I would like to figure out whether the browser session is brand new (user just fired up a browser and loaded my page) or a subsequent click-through.
How can this be done with JavaScript?
Instead of window.referrer try document.referrer. I got it to work for me in chrome
You can use window.referrer, although that's not a foolproof method, because some browser settings hide it for privacy purposes. It should work fine with most default settings, though.
It will give you undefined if the browser has just started up or the user has come there from a new tab, but keep in mind that if the user has a home page and comes to the site from there, it will give the home page. Also, if the user CMD/CTRL + clicks and opens in a new tab, it will throw undefined despite the fact that they clicked a link to get there.
With that said,
if(window.referrer){
//stuff to do if clickthrough
}else{
//stuff to do if new session
}
Demo
You could set a session cookie when the site loads on the initial page. Therefore when the site loads and you check if that cookie exists or not, you'll know whether it is a new session starting or not.
You can check for sessionStorage.length in your $(document).ready() function.
If the sessionStorage length is equal to 0, then you can probably set an item like the time where you can store the time at which the page got loaded using jQuery.now().
Next time, if the page reloads, you can check for the length which will not be 0, showing that the same session still exists.
$(document).ready(function(){
if(sessionStorage.length!=0){
//do something
}
else{
sessionStorage.setItem("time",jQuery.now());
}
}
I want to set a cookie when a visitor on the page closes the browser.
I used onbeforeunload method like this
<script language="JavaScript" type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
followed this link
But found out that even refresh of page or click on any hyper link on the page,pops up an alert.
I need to set cookie only when visitor clicks cross button of browser and not on page refresh.
I followed some of the links like the one above and another here. And found from the post that we can not differentiate between close and refresh. But those posts were 3-4 years back.
Is there is any way to differentiate these events using JavaScript or Jquery?
I'm afraid you have no way to tell.
The only thing you can do is overload clicks on links and set a flag. But you can never know if it is a refresh or a close...
Hmm, what about this:
Set a cookie onbeforeunload
Globally onload, check the timestamp of the cookie to see whether this was a link, or a new session
If the timestamp difference is only a few seconds, delete the cookie
Well, unload is called when browser is closed and onload is called when you try to reload. You can use these properties and set flags , and fire events accordingly
Browser close and reload Check this link for more details
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.