K
K
KatsuShooter2018-10-31 09:58:17
JavaScript
KatsuShooter, 2018-10-31 09:58:17

Scripts not working in Safari?

Good afternoon! I made a preloader, after loading the body, the preloader is assigned the done
HTML class:

<div class="hellopreloader" id="page-preloader">
  <div class="loader"></div>
</div>

Javascript:
<script type="text/javascript">


var preloaderDiv = document.getElementById('page-preloader');
var preloader = document.getElementById('page-preloader');
   
      document.body.onload =  function() {
        setTimeout(function () {
          
          if (!preloader.classList.contains('done')) {
            preloader.classList.add('done');
          }
        }, 1000);
        
      }
    </script>

The problem is that in Safari the class is not assigned and the preloader spins forever, in Chrome on the desktop everything is fine, on phones it is not shown at all. What is the reason
By the way, Safari throws such an error in the console
The source list for Content Security Policy directive 'script-src' contains an invalid source: ''strict-dynamic''. It will be ignored.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Larin, 2018-10-31
@fanrok

safari, as far as I remember, does not understand document.body.onload
try window.onload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question