I have created Login page, based on localStorage. On loading the page I have checked the value of localStorage. If I opened the web page in more than one tab and then I logo
You can use Storage events to be notified when localStorage values are changed.
function storageChange (event) {
if(event.key === 'logged_in') {
alert('Logged in: ' + event.newValue)
}
}
window.addEventListener('storage', storageChange, false)
If, for example, one of the tabs logs out:
window.localStorage.setItem('logged_in', false)
Then all other tabs will receive a StorageEvent
, and an alert will appear:
Logged in: false
I hope this answers your question!