I try to find information on how to read data stored in localStorage
it without having to reload the example page:
if (localStorage){
//Verificamos si soporta la caché local
//Como Saber si existe Sidebar
if(localStorage.getItem('Sidebar') !== undefined && localStorage.getItem('Sidebar')){
alert("Sidebar si existe en localStorage!!");
//Elimina Sidebar
localStorage.removeItem('Sidebar');
}
}
In this way I manage to verify and delete the data. Logically this way is only executed when the page loads.
What I need is a way that this verification is repeated until the data is obtained, something like a loop. I clarify the data to verify originates in another page in this way:
localStorage.setItem('Sidebar');
After completing an action.
Well, in short, I need a way to monitor the page until it returns the data.
I look forward to your opinions and answers, thank you very much.
You can subscribe to changes in local storage as follows:
The problem with this method is that it listens for changes made on other pages, not the current one:
In Spanish:
So you can try to check the information periodically if the change occurs within the same document. In that case I recommend you do it through an interval configured with
setInterval()
: