sandoche / Darkmode.js

🌓 Add a dark-mode / night-mode to your website in a few seconds
https://darkmodejs.learn.uno
MIT License
2.72k stars 176 forks source link

TypeError: null is not an object (evaluating 'document.body.insertBefore') #8

Open matiasmacera opened 5 years ago

matiasmacera commented 5 years ago

Im getting this error when trying to add the script

TypeError: null is not an object (evaluating 'document.body.insertBefore')

youcanping commented 5 years ago

script in body is OK

sandoche commented 3 years ago

Try loading the library with a function on window's load:

  function addDarkmodeWidget() {
    new Darkmode().showWidget();
  }
  window.addEventListener('load', addDarkmodeWidget);