对于这个问题,我在将一个函数绑定到Chrome 8.0.552.224中的Storage对象的change事件时得到了一个奇怪的结果.
考试:
<!DOCTYPE html>
<html>
<head>
<title>Chrome localStorage Test</title>
<script type="text/javascript" >
var handle_storage = function () {
alert('storage event');
};
window.addEventListener("storage", handle_storage, false);
</script>
</head>
<body>
<button id="add" onclick="localStorage.setItem('a','test')">Add</button>
<button id="clear" onclick="localStorage.clear()">Clear</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我会在第二个选项卡和第二个窗口上显示一个警告框,但不会在调用该事件的选项卡上显示(我点击了).据我所知,我应该看到三个警告框(每个标签打开一个).
这是一个错误吗?有其他人得到这种行为吗?如果不是你在运行什么版本?或者我刚刚完全错了?