I have played around with java script and it is working.
When the login page is loaded - it checks for the username element.
You will need to add this to every logon page - .html and .jsp
If the element exits, then add a true flag to the browser’s local storage.
//check for username element and set local storage item to true
if (document.getElementById('username')) {
localStorage.setItem('UsernameExists', 'true');
}
//clear username and password elements values. I'll explain why we need below.
window.addEventListener('beforeunload', function(event) {
document.getElementById('username').value="";
document.getElementById('password').value="";
});
in the startup.html file
You are adding script to check if a refresh has been performed and if the local storage item is true. IF they are both true, then it redirects user to the logon screen each time. This should work for time outs as well.
if (window.performance && window.performance.getEntriesByType) {
const navigationEntries = window.performance.getEntriesByType('navigation');
if (navigationEntries.length > 0) {
const navigationType = navigationEntries[0].type;
if (navigationType === 'reload') {
// Perform actions specific to a page refresh
console.log('This page was reloaded.');
if (localStorage.getItem('UsernameExists') === 'true') {
window.location.replace("http(s)://server/AwareIM/logon.jsp?domain=yourdomain");
}
}
// you can also include what happens if back button or forward button is clicked or if a natural navigation has occurred. this is not necessary for what I wanted to achieve, but have included it for completeness.
else if (navigationType === 'navigate') {
console.log('This page was a fresh navigation.');
}
else if (navigationType === 'back_forward') {
console.log('This page was accessed via back/forward buttons.');
}
else {
console.log('Navigation type:', navigationType);
}
}
}
else {
console.log('PerformanceNavigationTiming API not supported in this browser.'); //if the browser can't handle the command.
}
//need to set the local storage to false. This will allow the user to refresh as many times whilst logged into the app with no redirection.
if (localStorage.getItem('UsernameExists') !== null) {
localStorage.setItem('UsernameExists','false');
}
when the user logs out/times out the local storage is set to true again. This is why it is important to add the code above to all login files.
if the user hits the back button and refreshes the browser, the refresh code is invoked and because the local storage is set to true, it navigates the user back the the logon page.
if the use hits the back button enough times, they will be taken back to their very first logon page, but this time the username and password fields will be populated. which is not ideal. that is why we need the
document.getElementById('username').value="";
document.getElementById('password').value="";
in the login files so that when the user navigates away from the login page, the field values are blanked out.
I’ve tested this on a a windows pc using edge and chrome.