Localstorage data storage, time-consuming problems and how to judge the completion of data storage

now there is a requirement in the company"s project, that is, in case A, to jump to the external link, before the jump, save the current route to localstorage , but the actual test found that the data was not saved successfully, and after the jump was delayed, it was OK. However, this delay is written to death, and it may not work because of the computer or network speed, so I would like to ask if there is any API related to localstorage data storage time, or judge that the access is completed event.

post the relevant code:

locals.set("routerWhenFake",currentRoute);
$timeout(function(){
    window.location.href="http://www.baidu.com";
},100);

do me a favor, thank you!

Mar.13,2021

this is just a stored value. You haven't got the


how did you achieve this locals? The operation on localStorage is Synchronize, and this problem should not occur


external links if cross-domain, localstorge is not available


This specification does not require that the above methods wait until the data has been physically written to disk. Only consistency in what different scripts accessing the same underlying list of key/value pairs see is required.

does not wait to physically write to disk

may not work because of computer or network speed

this is not true, it's just about writing to disk. There is no other API , or you have another way of thinking.

reference link webstorage


there is nothing wrong with you in theory. You can print the stored values immediately after set. If there is any, this is not the problem.


write a monitor yourself. If you find value, jump to


first of all, all localstage are owned by Synchronize. You can see here

.
var a = function(){localStorage.setItem("a", 1); console.log(localStorage.getItem("a"))}
var i = 0;
while(i < 1000){
    a();
    i += 1;
}
Jump directly after

setItem.

Menu