0

I have a day counter in a server and it works. But if I open another tab or window browser the counter is displayed but with a difference in time. What I want to do is to display the same values in both browser windows or tabs.

I tried to use sessionStorage and reload the document often but it doesn't run as I want, it displays the values desynchronized.

The code is:

function altra_finestra()
{
  var n;

//reload the document in order to display the same values
if(sessionStorage.n === 1) location.reload(true);
else sessionStorage.setItem('n', 1);

}

//display the values of the counter. It works
function mostrar_dies()
{

  altra_finestra();

  setTimeout(function ()
  {

    if((i > 0) && (spandies >= 0) && (spanhores >= 0) && (spanminuts >= 0)) 
    {
        i--;

        spansegons = document.getElementById('segons').innerHTML = i;

        //more code that works 
    }   

        if(spandies >= 0) spandies =      
        document.getElementById('dies').innerHTML = spandies;
        if(spanhores >= 0) spanhores = 
        document.getElementById('hores').innerHTML = spanhores;
        if(spanminuts >= 0) spanminuts = 
        document.getElementById('minuts').innerHTML = spanminuts;
    }


        mostrar_dies();

}, 1000)

}

Why I can't display the same values in several browser windows or tabs? I haven't errors in the code.

Thanks.

axmug
  • 476
  • 2
  • 10
  • 26

0 Answers0