script where a given time and day of the week redirects the user to a specific page

Asked

Viewed 42 times

0

I am trying to create a script so that one page redirects the user to another depending on the day of the week and the time. I found something, but it didn’t work:

` Function Checktime() {

var Saticdate = new Date(); var mdia = Saticdate.getDate(); var mdiasemana = Saticdate.getDay(); var mhora = Saticdate.getHours() var mminutos = Saticdate.getMinutes();

Else if(mdiasemana == 0) {
window.open("https://google.com"); }

Else if(mdiasemana == 4 && mhora >= 14 && mminutos >= 00 && mhora <= 15 && mminutos <= 05) {
window.open("https://apple.com/br"); } Else if(mdiasemana == 4 && mhora >= 15 && mminutos >= 06 && mhora <= 16 && mminutos <= 45) {
window.open("https://microsoft.com"); }

Else { window.setTimeout("Checktime();", (60 * 1000)); } }

Checktime(); `

1 answer

2

window.setInterval(function(){ // Setando intervalo de tempo
    var date = new Date(); // Criando o Objeto Date();
    if(date.getHours() === 20 && date.getMinutes() === 35){ // Verificando a hora
        // Executando o codigo
        window.open("www.google.com");
    }
}, 60000); // Verificando o codigo a cada 60000 Milisegundos (1min)

There will be a delay to run the script as it is checked every minute. This is done so that the same site is not opened 2 times in the same minute

Some browsers may block the opening of the new Window because of CORS (Cross-origin Resource sharing)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.