localStorageの変更時に発生するイベントは、Firefoxでは情報が不足しているようです。localStorageの 'storage'イベントの未定義プロパティ
私は、次のイベントハンドラを設定:このによってトリガされなければならない
function storageEventHandler(e){
alert("key " + e.key);
alert("oldValue " + e.oldValue);
alert("newValue " + e.newValue);
alert("url " + e.url);
}
window.addEventListener('storage', storageEventHandler, false);
:。しかし
localStorage.setItem('foo', 'bar');
、イベント内のすべてのプロパティ(例えばe.keyをし、その他すべて)はすべて定義されていません。私はfirefox 3.16を使用しています。なぜイベントのプロパティは未定義ですか?
EDIT。ここに私が使用しているすべてのコードがあります。ストレージイベントも
のFirefox 3.16ではなく、Firefoxの4.0b8で火災、重要な、私は、ファイルからそれを実行しているXAMPP http://localhost/index.html からそれを実行しています://それはlocalStorage Getting NULL?
<!DOCTYPE html5>
<html lang="en">
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function() {
var edit = document.getElementById('edit');
$(edit).blur(function() {
localStorage.setItem('todoData', this.innerHTML);
});
// when the page loads
if (localStorage.getItem('todoData')) {
edit.innerHTML = localStorage.getItem('todoData');
}
window.addEventListener('storage', storageEventHandler, false);
function storageEventHandler(e){
alert('localStorage event fired')
}
});
</script>
</head>
<body>
<header>
<h1> My Simple To-Do List </h1>
</header>
<section>
<ul id="edit" contenteditable="true">
<li></li>
</ul>
</section>
<em>Add some items, and refresh the page. It'll remember what you typed.</em>
</body>
</html>
EDIT#2ダイ作ります:ここでは、ブラウザ間の問題を示して単純な例は...だ
<html>
<head>
<script>
function storageEventHandler(e){
alert('localStorage event fired')
}
window.addEventListener('storage', storageEventHandler, false);
localStorage.setItem('foo', 'bar');
alert('ok')
</script>
</head>
<body>
Test
</body>
</html>
ありがとう!非常に有益であり、感謝しています:) – Alexis
残念ながらFirefox 4では何も動作しません=( – Alexis
@Alexis K:テストケースを持っていますか?どのバージョンのテストですか? – Nickolay