R
R
RaininoYT2020-02-07 21:20:34
JavaScript
RaininoYT, 2020-02-07 21:20:34

Why is NaN displayed instead of numbers in JS timer in Safari?

There was a problem. Created a JS timer. It works correctly in all browsers, and Safari writes NaN instead of numbers. There are no errors in the console. I am attaching the timer code.

<script>
        var YearS = 0;
        var MonthS = 0;
        var DayS = 0;
        var HourS = 0;
        var MinS = 0;

        function updatecountdown() {
            var now = new Date();
            timeN = (now.getMinutes()) + now.getHours() + now.getDate() + now.getMonth() + now.getFullYear();
            time = (MinS-1) + HourS + DayS + MonthS + YearS;
                if(time == timeN){
                    window.location.reload();
                }
            setTimeout(updatecountdown, 1000);
        }
        updatecountdown();

        var deadline= <? echo '"'.$mm.' '.$dd.' '.$yy.' '.$hh.':'.$mi.':00"'; ?>;
        initializeClock('countdown', deadline);
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-02-07
@Aetae

It can be assumed that Date.parse in safari cannot read the . Try like this:'"'.$mm.' '.$dd.' '.$yy.' '.$hh.':'.$mi.':00"'

var deadline= new Date(+YearS, MonthS-1, +DayS, +HourS, +MinS);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question