skip to Main Content

im trying to make a my index.html file redirect o another html file after i reach a certain date and time (noob here)

this is my code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>title</title>
    <script language="javascript">
        var currentdate = new Date();
        var datetime = "Last Sync: " + currentdate.getDate() + "/" + (currentdate.getMonth()         + 1) +
        "/" + currentdate.getFullYear() + " @ " +
        currentdate.getHours() + ":" +
        currentdate.getMinutes();

        var dateAfter = new Date('2023-08-5T00:00:00');

        if (currentdate > dateAfter) // Datum omschakeling
{
        location.href = "redirect.html";
}
    </script>
</head>
<body>

</body>
</html>

And i should go to redirect.html but its not

2

Answers


  1. You should add window object:

    window.location.href = "YourPathFile";
    
    Login or Signup to reply.
  2. Your dateAfter is invalid.

    change

    var dateAfter = new Date('2023-08-5T00:00:00');
    

    to

    var dateAfter = new Date('2023-08-05T00:00:00');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search