i have a confirm message which is showing when page is idle for some time in javascript . The confirm pop up came once the session time out. At that time if we give any response to the confirmation pop up it will do the corresponding process. My requirement is if we are not giving any response means i need to force the browser to close.. can anybody help me on this?
window.setTimeout('checkIfContinue()', 5*1000);
var sFlag=0;
function checkIfContinue()
{
window.setTimeout('idleTime()', 5*1000);
if(sFlag == 0)
{
sFlag = 1;
if(confirm("Your Session Expired!. Do you wish to continue?"))
{
window.setTimeout('checkIfContinue()', 5*1000); //start the timer again
sFlag = 0;
}
else
{
// logout
}
}
}
This is the query which i used to call the pop up after session time out. I need to close the browser when no responses given to the responses..
I believe that in this case you'll need to use some other than system dialog.
E.g. showing a DIV with the question and buttons, so you'll be able to close the window even with opened "dialog".
In jquery, there are plugins for this kind of dialogs like Jquery UI, or select on of theese:
http://choosedaily.com/1178/15-jquery-popup-modal-dialog-plugins-tutorials/
Also remember, that the browser window can be closed by script only when it was opened by the script. Otherwise the function window.Close(); will ask the user about closing.
Related
I want to restrict the page refresh only when we doing this by clicking the refresh icon at the top left side of the browser.
I have tried more available options like,
'beforeunload' event, which can fire on each time of unloading(refresh, navigation, close) the browser.
Inside the event, I have tried 'window.performance.navigation.type' and window. performance.getEntrieaByType('navigation').map(nav=>nav.type) options. But both aren't giving the correct result. On each actions like "refresh", "navigation" and "close" getting the same result. Also sometimes getting different result. So I amn't trusting the options.
So can anyone help me to get the correct option to detect the refresh action done by browser refresh icon?
I am using react application.
window.onbeforeunload = ()=>{
localStorage.setItem("unload",Date.now());
}
useEffect(){
let last_unload = localStorage.getItem('unload');
let decided_time = 1000;
if(last_unload){
// means the user have closed the page
if(Date.now() - parseInt(last_unload,10) <= 1000)
{
// this is a refresh
console.log('refresh handling code')
}else{
// It's a new session, means user came to page, closed the browser, now came back after a long time
}
}
}
Generally the answer from here
should work but because you are stating that window.performance is ambiguous in your case try something like this. Let me know if this helps!
Is there anyway to check twitter login status like FB.getLoginStatus(response)? I want to hide the pop-up window if the user already logged. Right now the user has to click the button and every time the window will pop up whether the user logged or not:
$('#twitter').change(function() {
if($(this).prop('checked')){
hello('twitter').login(function(e){
if(e.error){
$('#twitter').prop('checked',false);
}else{
var twitter_oauth_token = hello('twitter').getAuthResponse().oauth_token;
var twitter_secret = hello('twitter').getAuthResponse().oauth_token_secret;
}
});
}else {
}
});
Looking for the same. I remember doing it years ago with testing image cache, but I am pretty sure that hack is long gone by now. I will have to check some old code. If only I could think of the project I used it on.
I am developing a project where user gets a conformation page. I want user not to click back or close tab or reload.
Now either I need to disable the browser features or get back button,tab close event, or reload event to java script so that I could take the needed steps to prevent my data to get lost.
I have used this:
window.onbeforeunload = function()
{
return "Try This";
};
But this get called even when I click a button that redirects the page.
If you just want to have the alert, understanding that the user is ultimately in control and can bypass your alert, then do what you're doing but use a flag that disables it when you're navigating and don't want the alert. E.g.:
var warnWhenLeaving = true;
window.onbeforeunload = function() {
if (warnWhenLeaving) {
return "your message here";
}
};
then in a click handler on the link/button/whatever that moves the user on that you don't want this to pop up on:
warnWhenLeaving = false;
In a comment you asked:
can i know that what user has clicked when alert is generated with this function. That is can i know what user has clicked (leave this page/stay on page)
The answer is: Sort of, but not really; you're almost certainly better off not trying to.
But: If you see your onbeforeunload function run, then you know the user is leaving the page and the browser is likely to show them your message. The browsers I'm familiar with handle the popup like an alert: All JavaScript code on the page is blocked while the popup is there. So if you schedule a callback via setTimeout, you won't get the callback if they leave and you will if they stay:
window.onbeforeunload = function() {
if (warnWhenLeaving) {
setTimeout(function() {
display("You stayed, yay!");
}, 0);
return "No, don't go!";
}
};
Live Example
So in theory, if you get the callback, they stayed; if you see an unload event, they left. (Note that there are very few things you can do in an unload event.)
I've tried that on current Chrome, current Firefox, IE8, and IE11: It works on all of those. Whether it will work in the next release of any of them is anybody's guess. Whether it works reliably on mobile browsers is something you'd have to test, and again could change.
I have this javascript method that needs to run in the background
window.setInterval(function(){
validateCaseStatus();
}, 3000);
On the same page I have a button that asks the user if he wants to submit uploaded documents. But I noticed when the popUp msg(alert) is up the script on the page wont run.
Is there a way to keep the script running?
I use this method to check if the case status is changed and disable window.onbeforeunload.
My question is if theres a way I can keep the script above running even when a popUp alert is shown.
//cancels onbefore close popup when docs are submitted
function validateCaseStatus(){
caseStatus = sforce.apex.execute("IFAP_WebService","CheckCaseStatus", {!$caseId});
if (caseStatus == "Uploaded" || caseStatus == "Submitted")
{
submitted = true;
window.onbeforeunload = null;
validateCaseStatus = null;
}
}
Try using WebWorkers. It's a new html5 concept, and requires a bit more work, but they are very easy to understand and very helpful. See https://developer.mozilla.org/en-US/docs/DOM/Using_web_workers?redirectlocale=en-US&redirectslug=Using_web_workers http://ejohn.org/blog/web-workers/ and http://www.html5rocks.com/en/tutorials/workers/basics/
I am building a web app and I am trying to do a function where there is a popup confirm box that shows after the user has been inactive for 10 minutes. When the popup opens the user can choose to continue being logged in or not. I need this box to close down after 1 minute if they have not answered the popup. How can I do this. Everything else works fine.
This is my code:
function checkTime () {
setTimeout (function () {
var dialog = confirm ("Do you want to continue being logged in?");
if (dialog == true) {
checkTime ();
} else {
window.location = 'LOGOUT URL';
}
}, 10000);
};
You cannot do that with the native confirm() as it stops JavaScript run on that page until the user has clicked on it.
So, You have to create a plugin for confirm-box or try someone else.
And they often look better, too. :)
you can't make the confirm close itself - as a thought path my bank has the same sort of thing on their on-line banking system - quite simply if you walk away and come back, it you've been longer than 10 minutes it doesn't matter what you chose it apologizes and logs you out anyway
the dialog requires human interaction it can not be overridden for security reasons. in order to do what you are trying to you would need to use a modal solution (this can be achieved with a small amount of js and some css if you don't want to use a third party solution)
I know it's not the answer you were looking for I'm sorry but hopefully it gives you some ideas for options