How to save changes even after page reload?

Good day to everyone!

While developing an extension for Chrome, I encountered the following problem: There is some field F. It has a status indicator. There are two status options: green and red (default). As soon as the field value has been updated - the status indicator should turn green.

Up to this point, everything is clear. I use the $.change () method and everything works. But the problem is that after the page is reloaded, the status indicator turns red again.

Question: How to ensure that, after changing the field, the status indicator remains green even after reloading of the page? Some way to remember the result.


for a purely javascript application, i’d rather use localstorage than cookies, because the server doesn’t need the information, but either works.

1 Like

Have you used localstorage before?

Thank you for the link. I am using the localstorage for the first time. I tried a lot of variants how to structure the query, but unfortunately, it doesn`t work. And more, there are no errors and warnings during the compile.
Here my final code: {
        feedViewElement.change(function() {
                liElement.css("list-style-image", passedStateImgUrl);
                aElement.attr("title", passedStateText);

What I do wrong?

Hi @artemzaharchuk1, the chrome storage API is not the same as the regular web storage API, so writing to the localStorage won’t trigger change events on the chrome storage; also you have to use either storage.local or storage.sync:
// Then somewhere else{ foo: 'bar' })

Also note that you have to register the storage permission in the extension manifest.

Yeb, localstorage can solve your problem

I don’t think this is a correct implementation of localStorage.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.