Forum Moderators: open
I am trying to use the window.setTimeout feature so that a message pop-up with yes/no appears on the screen asking whether to extend the session.
*If yes is clicked, the current page reloads.
*If no is clicked, nothing happens. (the session will expire anyway).
Could not figure out the code.
Sorry if it had been post before.
if (condition) {
// true
}
So
function reloadPage(url) {
var ok = confirm('Extend session?');
if (ok) { document.location=url; }
return false;
}
should do it. Put that in a document with this to test.
<p><a href="some-file.html" onclick="return reloadPage(this.href);">test</a></p>
if (confirm('continue session?')) {
setTimeout(window.reload, 5000);
}
if you wanted this to appear sometime after the page loaded:
setTimeout(function () {
if (confirm('continue session?')) {
setTimeout(window.reload, 5000);
}
}, 1000 * 60 * 9);
Also note, avoid using the quoted string version of setTimeout. That is, instead of this:
setTimeout("somefunction()", 1000);
pass in a function reference instead:
setTimeout(somefunction, 1000);