Javascript &引用;储存;在firefox中的同一选项卡上激发的事件

Javascript &引用;储存;在firefox中的同一选项卡上激发的事件,javascript,local-storage,Javascript,Local Storage,2013年,我编写了一段代码,防止用户在同一个域上打开第二个浏览器选项卡,直到一年前,它一直运行良好。它基于第二个窗口写入本地存储时应该触发的“存储”事件。代码如下: $(function(){ var this_tab_key = randomString(30); var listener = function(e){ if(e.key=='test_block' && e.newValue != this_tab_key)

2013年,我编写了一段代码,防止用户在同一个域上打开第二个浏览器选项卡,直到一年前,它一直运行良好。它基于第二个窗口写入本地存储时应该触发的“存储”事件。代码如下:

$(function(){

    var this_tab_key =  randomString(30);
    var listener = function(e){

        if(e.key=='test_block' && e.newValue != this_tab_key)
        {
            STOP_AJAX_CALLS = true;
            var div = $('<div id="modal_block" style="top:0px;left:0px;position:absolute;width:100%;height:100%;opacity:0.5;background-color:black;z-index:12000"></div>');
            div.append('<div style="position:absolute;top:50%;left:0;width:100%;font-size:60px;margin-top:-50px;text-align:center;line-height:50px;" >Please close this tab/windows <br>as another one has been opened</div>');
            $("body").append(div);
            if (window.removeEventListener) 
                window.removeEventListener("storage", listener);
            else
                window.detachEvent("onstorage", listener);
        }
    };

    if (window.addEventListener)
        window.addEventListener("storage", listener);
    else
        window.attachEvent("onstorage", listener);

    localStorage.setItem('test_block', this_tab_key);
});
$(函数(){
var this_tab_key=randomString(30);
变量侦听器=函数(e){
if(e.key=='test\u block'&&e.newValue!=此选项卡\u键)
{
STOP_AJAX_CALLS=true;
var div=$('');
div.append('请关闭此选项卡/窗口,因为另一个选项卡/窗口已打开');
$(“正文”)。追加(div);
if(window.removeEventListener)
removeEventListener(“存储”,侦听器);
其他的
detachEvent(“onstorage”,侦听器);
}
};
if(window.addEventListener)
addEventListener(“存储”,侦听器);
其他的
attachEvent(“on存储”,侦听器);
setItem('test_block',此_tab_键);
});
最近发生的情况是,即使我只打开了一个选项卡,也会触发“存储”事件,但并不总是这样,而且它通常在我打开选项卡3/5分钟后发生。没有ajax/ws调用,站点中一般没有活动。页面中没有iframe,因此没有其他“窗口”对象。 这似乎只发生在firefox上,但他们告诉我,这也可能发生在chrome上,即使我从未亲眼见过。 你知道这里发生了什么事吗


提前感谢

嘿@Massimo Paon,你能解决这个问题吗?我现在面临同样的问题。谢谢