vendredi 2 février 2018

Check time and load content accordingly jQuery

I am building a website (personal project) and I'm trying to achieve the following: if the user goes on any page in certain hours (eg: between 22 and 6) it shows a message instead of the desiderd page; if he/she visits the page at other times during the day, the page loads without any message. The message should replace the entire content of the pages in certain hours.

Right now my code works fine on the index, but I want it to become as generic as possible so that the same code can work on all pages.

If this sounds silly it's probably because I am almost a complete newbie in web programming.

Thanks in advance

Here's my code so far:

var objDate = new Date();
var hours = objDate.getHours();
$( document ).ready(function() {    
    if(hours >= 06 && hours <= 10){
        $("#content").load("current-page.html"); // Load desired page, so name has to be dynamic I guess (?)
    }
    else{
        $("#content").load("/message.html"); // Load custom message
    }
});    




Aucun commentaire:

Enregistrer un commentaire