Tips for redirecting once a JavaScript timer has run out?

Looking to update the code once the timer (See code) has run out. Currently, I am working on an exciting auction project for a friend and when the timer expires, I want to change the page so that no more bids can be placed. All bids are time-sensitive, so I could manually check if any bids were placed after expiration, but that seems cumbersome. It would be great if it could be done automatically. Currently, it displays "EXPIRED!" when the timer ends, but what should I replace it with to prevent further bidding?

If you need to see more code, please let me know. Thank you in advance.

CountDownTimer('01/31/2016 7:1 PM', 'countdown');

function CountDownTimer(dt, id)
{
    var end = new Date(dt);

    var _second = 1000;
    var _minute = _second * 60;
    var _hour = _minute * 60;
    var _day = _hour * 24;
    var timer;

    function showRemaining() {
        var now = new Date();
        var distance = end - now;
        if (distance < 0) {

            clearInterval(timer);
            document.getElementById(id).innerHTML = '<span class="date">EXPIRED!</span>';

            return;
        }
        var days = Math.floor(distance / _day);
        var hours = Math.floor((distance % _day) / _hour);
        var minutes = Math.floor((distance % _hour) / _minute);
        var seconds = Math.floor((distance % _minute) / _second);

        document.getElementById(id).innerHTML = 'Time Left = ';
        document.getElementById(id).innerHTML += '<span class="date">' + days + ' D</span>';
        document.getElementById(id).innerHTML +=  '<span class="date">' + hours + ' H</span>';
        document.getElementById(id).innerHTML +=  '<span class="date">' + minutes + ' M</span>';
       // document.getElementById(id).innerHTML +=  '<span class="date">' + seconds + ' S</span>';
    }

    timer = setInterval(showRemaining, 1000);
}

Answer №1

inside your script:

  if (distance < 0) {

        clearInterval(timer);
        document.getElementById(id).innerHTML = '<span class="date">EXPIRED!</span>';

        window.location.href="Your page to go to";

        return;
    }

Make sure to include the redirect code before the return statement.

Note that the message "Expired!" may not be visible on the page as the redirection will happen immediately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

(Critical) Comparing AJAX GET Requests and HTTP GET Requests: identifying the true client

When a typical GET request is made through the browser, it can be said that the browser acts as the client. However, who exactly serves as the client in the case of a GET request via AJAX? Although it still occurs within the browser, I am intrigued to delv ...

Determining the selected option's value made by the user

On my index.php file, which contains the form and function, I have the following code: $(function() { $.ajax({ type: "POST", url: "invtype.php", data: "getrevenuetype=true", success: function(b){ $("#revenue ...

Mastering JSON looping for each distinct group

I'm new to JavaScript and recently encountered an issue with JSON. Here is the object I am working with: var users = [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName": ...

`Creating a fluid MySQL table using JavaScript`

One of the challenges I'm facing involves working with a MySQL table that consists of 3 columns: MySQL db table +--+----+-------------+ |id|data|display_order| +--+----+-------------+ |0 |0 |2 | +--+----+-------------+ |1 |1 |1 ...

Stylish hover effects displayed on disabled button using Styled Components

I am currently working on a button using Styled Components. However, even when the button is in a disabled state (:disabled), it still exhibits hover behavior that should not be present. I am wondering if there is a proper way to prevent hover effects when ...

Web Browser Fails to Set Cookie during an Ajax Request

I am facing a perplexing issue. I have an AJAX call that triggers the processing of a login form and generates a cookie upon successful login. However, the web browser is failing to recognize the cookie. Upon troubleshooting, I have narrowed it down to so ...

Having trouble getting the items to show up on the canvas

I have been struggling to implement JavaScript on a canvas in order to display mice in the holes using the mouse coordinates. Despite trying many different methods and spending close to a month on this project, I still can't seem to get it to work acr ...

Addressing the "Your tests are loading..." Problem in Cypress Following Redirect from PayPal Login

I've encountered a challenge with Cypress tests while trying to log into the PayPal sandbox environment using cy.origin(). The issue arises after successful login when the tests get stuck at "Your tests are loading...". This problem occurs after the p ...

Display handpicked ionic list view

I have put together a demonstration using this (demo) to showcase the issue I am facing. Within this demo, there is a page with a list, a button located in the header that checks the attribute of an <ion-checkbox>, and a checkbox next to the list v ...

Unable to replicate the functionality of the tab key using jQuery for the enter key

How can I focus on the first input ('Qtd on the table') after pressing enter on the 'Buscar' input? I've tried various solutions like $(this).nextAll('input').first().focus(); $(this).next('input:text').focus ...

Using JSON.stringify to format data and making an asynchronous $http request

I am working with a JavaScript string that looks like this: user_fav = "21,16"; I need to process this string through a function so that it becomes a JSON array with an id key, like this: {"id":21},{"id":16} This JSON array is then used in an $http req ...

Ways to incorporate lighting into the instancing shader

Is there a way to incorporate ambient and directional lighting into the shader when using InstancedBufferGeometry? For example, I am looking to add lighting effects to a specific instance, like in this example: Below is the vertex shader code: precision ...

When attempting to watch a video on iOS using the YouTube embed player, clicking on the red button will not initiate playback

Just a quick question for you all. I've encountered an issue with the Youtube player on my HTML website when trying to play videos on IOS devices. It seems that tapping on the red "play" button does not start the video, but tapping on the preview ima ...

Ways to showcase the refined object array upon clicking a button in Angular

I have been working on a project to create a task management system. The project consists of two main components: itemList and item. The itemList component takes input values for tasks and displays them in the item component. https://i.sstatic.net/SaRNMm. ...

Navigating with React-router can sometimes cause confusion when trying

I'm having trouble with my outlet not working in react-router-dom. Everything was fine with my components until I added the Outlet, and now my navigation component isn't showing even though other components are rendering. import Home from ". ...

Sort slider items using Show/Hide feature in bxSlider

I am using a bxslider on my website with specific settings: $('#carousel').bxSlider({ slideWidth: 146, minSlides: 2, maxSlides: 6, speed:500, adaptiveHeight: true, moveSlides:3, infiniteLoop : false, hideContr ...

Error: Unable to access unknown properties (reading 'extend')

Struggling to integrate the Vuetify library into my current Vue 3 project, encountering complications. An error message popped up post-compilation: vuetify.js?ce5b:42021 Uncaught TypeError: Cannot read properties of undefined (reading 'extend') ...

obtain the specific attributes of the button that was clicked using jQuery

My goal is to preview an image before uploading it to the server, and this is the HTML code I am using: <html> <script> function readURL(input) { if (input.files && input.files[0]) {.......}} $("#selectedFile").change(functio ...

Step-by-step guide on mocking an asynchronous function in nodejs with jest

Within this function, I need to mock the httpGet function so that instead of calling the actual function and returning its value, it will call a simulated function fetchStudents: async(req,classId) => { let response = await httpGet(req); return r ...

Executing server-side operations after a request has been sent

Recently, I discovered that entering the following URL into my browser results in a .csv file being downloaded to my Downloads folder on My Computer. The word YHOO represents the stock symbol for Yahoo: Is there a way for me to replicate this process on m ...