Pergunta

I'm not a programmer so forgive the newbi-ness...

I've observed an interesting page refresh concept on CMSWire.com. Basically, they're refreshing the page after 15 minutes using javascript. However, there's a clever catch. It seems they're only doing this for about 50% of their visitors. The method - generate a random number between 1 and 1000 then serve the refresh code for anyone over 500 (or something like that).

I'd love to employ a similar technique but have a clue how to write the code...

Anyone care to give it a whack?

Foi útil?

Solução

solution sound really simple to me:

Something like this (embedded in your Javascript) will do the trick:

var rnd = Math.random() * 1000;
var timeToReload = 60 * 1000 * 15;
if (rnd > 500) {
    setTimeout(function () {
        location.reload();
    }, timeToReload);
}

Cheers,
Florian

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top