问题描述
我正在使用 Safari webkit 的引擎以及 HTML5 和 JS 来创建一个离线应用程序,现在我正在使用 sessionStorage
数组来存储我的应用程序的状态(模拟).
I'm using Safari webkit's engine together with HTML5 and JS to create an offline application now I'm using the sessionStorage
array to store status of my application(simulation).
存储数据与检查器正常工作,功能正常工作,事件处理程序没有响应.
The storage data works fine with the inspector the functions work fine it's the event handler that isn't responding.
Anurag
在 http://jsfiddle.net/pvRgH/进行的测试 在这里也不起作用:
The test preformd by Anurag
at http://jsfiddle.net/pvRgH/ also doesn't work here:
window.addEventListener('storage', storageEventHandler, false);
function storageEventHandler(evt){
alert("storage event called key: " + evt.key );
switch(evt.key){
case 'bat1':
case 'bat2': batteryDCMeter(); break;
case 'extPowerOn': rechargeBattery(); break;
}
}
function load()
{
dashcode.setupParts();
//set HTML 5 key/value's
sessionStorage.setItem('bat1', 'OFF');
sessionStorage.setItem('bat2', 'OFF');
sessionStorage.setItem('bat1DC', '26.2');
sessionStorage.setItem('bat2DC', '26.2');
}
function bat1OnOff(event)
{
if(sessionStorage['bat1'] == 'OFF'){
sessionStorage['bat1'] = 'ON';
}else{
sessionStorage['bat1'] = "OFF";
}
}
function bat2OnOff(event)
{
if(sessionStorage['bat2'] == 'OFF'){
sessionStorage['bat2'] = 'ON';
}else{
sessionStorage['bat2'] = "OFF";
}
}
推荐答案
仅当存储事件从另一个窗口触发时才会触发存储事件处理程序.
Storage event handlers only fire if the storage event is triggered from another window.
如何在 Safari 5+ 中每次更新 localStorage 时触发事件?
这篇关于HTML5/JS 存储事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!