私はFirefox拡張機能を作成しています。ブラウザ全体のグローバル変数として localStorage を使用したい。ただし、保存されたタブでのみ機能しています。他のタブでこの値を読み取ることができません。任意のタブからアクセスできるようにするにはどうすればよいですか、または考えられる問題は何ですか?
私はそれを次のように使用します:
localStorage.getItem('variable')
localStorage.setItem('variable','value')
より正確には、ページが読み込まれたときに JavaScript コードをページに挿入しています。挿入されたコードから、値をローカルストレージに保存したいと思います。
タブの URL が異なります。私のコードは、ページがロードされたときにローカルストレージを使用しようとしています。ただし、次のように localStorage 値が存在するかどうかを確認します。
if(localStorage.getItem('variable')){ ... }