I'll try to delete a localStorage Item in JS with my Chrome/Firefox extension, but it seems like it won't work, and now I would like to know how can I debug this problem, here my code from my popup.js:
var btn = document.createElement("BUTTON");
btn.innerText = "Delete matchs";
btn.onclick = function () {
localStorage.removeItem('save_to_storage');
};
my popup.html:
<!DOCTYPE html>
<html lang="de">
<head>
<script src='popup.js' defer></script>
</head>
<body>
<div id='button'></div>
</body>
</html>
If I press the button Delete matchs
the save_to_storage
item still appears in my developer tools, but if i type directly into the console localStorage.removeItem('save_to_storage');
it works as expected. I test it in firefox and chromium.
I also tried to get the value of this item by using alert(localStorage.getItem('save_to_storage'));
instead of localStorage.removeItem('save_to_storage');
in my popup.js but this alert was empty.
Can it be that my popup.js can't access this item? and if yes how can I solve this?
Test Enviroment:
Chromium Version 92.0.4515.107 (Offical Build) Arch Linux (64-Bit)
Mozilla Firefox 90.0.2 (64-Bit) for Arch Linux
Regards
Lucki1000
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment