Microsoft Edge: local/session storage are not working in a new tab

前端 未结 2 856
忘掉有多难
忘掉有多难 2021-02-12 09:47

I\'m working on a Web Application hosted in Azure. I\'ve tried it on MS Edge (build 20.10525.0.0) and got the following problem.

I have a link with target _blank to ope

2条回答
  •  温柔的废话
    2021-02-12 10:28

    If window A created window B then the storage event gets trigger

    try it out with this code

    create a file called a.htm and add this script in

    (function() {
        function write(s) {
            var d = document.createElement('div');
            d.innerHTML = s;
            document.body.appendChild(d);
        }
    
        var w = window.open('','window_b');
        if (w.location.host === '') {
            w.location.href = 'http://localhost/b.htm';
        }
    
        if (window.localStorage) {
            setInterval(function() {
                var now = (new Date()).toTimeString();
                localStorage.removeItem('date');
                localStorage.setItem('date', now);
                write('fired on ' + now);
            }, 3000);
        }
        else {
            write('local storage not detected!');
        }
    })();
    

    create a file called b.htm and add this script

    (function() {
        function write(s) {
            var d = document.createElement('div');
            d.innerHTML = s;
            document.body.appendChild(d);
        }
    
        window.addEventListener('storage', function(e) {  
            e.newValue && write('received ' + e.newValue);
        });
    
    })();
    

    then just browse to a.htm

提交回复
热议问题