【发布时间】:2010-08-25 04:50:34
【问题描述】:
我已尝试关注the examples on the Safari Developer Site。
文档建议像这样添加事件侦听器:
window.addEventListener('storage', storage_handler, false);
然后像这样设置你的处理函数:
function storage_handler(evt)
{
alert('The modified key was '+evt.key);
alert('The original value was '+evt.oldValue);
alert('The new value is '+evt.newValue);
alert('The URL of the page that made the change was '+evt.url);
alert('The window where the change was made was '+evt.source);
}
但我似乎无法让此代码在我的机器(OS X 10.6、Safari 5.01)和我的 iPhone 3GS(iOS 4.02)上的 Safari 上运行。
This article 提供了一个单独的方法:
window.onload = function() {
...
document.body.setAttribute("onstorage", "handleOnStorage();");
}
function handleOnStorage() {
if (window.event && window.event.key.indexOf("index::") == 0){
$("stats").innerHTML = "";
displayStats();
}
}
但我也没有运气。
我做错了吗?这是一个错误吗?
【问题讨论】:
-
我为您修复了您问题中的链接;一旦您获得更多代表,您应该能够很快添加更多链接。遗憾的是我不知道你的问题的答案。希望其他人可以提供帮助!
-
一个很好的演示及其代码 sn-p 已经可用here 这有助于理解这个概念及其工作原理。 html5demos.com/storage-events
-
你仍然有这个链接,这可能有助于很好地理解 sessionStorage nczonline.net/blog/2009/07/21/introduction-to-sessionstorage
标签: html safari local-storage