Detect if Chrome is recovering from yesterday

I have a form with a date input field. If you load a page, the entry is populated with the current date. But if Chrome starts and restores the last open tabs from yesterday, there is always a date from yesterday in the form. If I reload the page, it will display the correct date. But I would like Chrome to show the current date right away.

Any clever idea how to fix this?

Refresh : Page is set to cache-control:no-cache, private.

+6
source share
2 answers

JavaScript . , . , JavaScript , . , :

<input id="form_date" name="form_date" type="hidden" value="2017-12-19 17:52:08">
<script>
    // Day compare
    Date.prototype.sameDay = function(d) {
        return this.getFullYear() === d.getFullYear()
            && this.getDate() === d.getDate()
            && this.getMonth() === d.getMonth();
    };
    var x_today = new Date();
    var x_page_date = new Date($('#form_date').val());
    if (console && !x_today.sameDay( x_page_date )){
        console.log("Old page!");
        console.log('page date: ', x_page_date);
        console.log('today: ', x_today);
    }
</script>

, .

+2

ajax, .

-2

All Articles