The localStorage function does not work

Asked

Viewed 346 times

0

I have this code:

localStorage.setItem("name", "pedro");

Only when I see application/Local Storage/File is not created Key nor the Value and gives me an error:

test.html:13 Uncaught Domexception: Failed to read the 'localStorage' Property from 'Window': Access is denied for this Document.

What am I doing wrong?

  • 3

    Have you seen first if your browser is compatible? localStorage brower compatibility

  • 2

    It may be that your browser has the option "Block third party cookies and website data" enabled. Disable and should work normally.

  • 1

    You need to share the browser you are using and also the operating system. Both have a big influence on this.

  • Probably the answer from @Leonardotandeli is correct

1 answer

1

This error occurs in Chromium based browsers such as Chrome, Opera, etc

As explained in: https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

In the current version of Chrome browser specifically, the setting of COOKIES and other data is at: chrome://settings/content/cookies, the error will occur when it is this way:

Chrome

The opera is located in opera://settings/content/cookies, as in the image:

Opera

Being enabled will get this Exception, so just disable it (default is disabled).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.