Darkmode bug chrome

Hey guys :slight_smile:

I attempted to deploy a Dark Mode following the advice on the community by @artur, from this code, which I inserted into the footer of my website. I don’t understand it doesn’t work

<script src="<https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js>"></script>
<script>
  function addDarkmodeWidget() {
    new Darkmode().showWidget();
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>

I get this error in Google Chrome Console

Uncaught ReferenceError: Darkmode is not defined at addDarkmodeWidget

Any ideas ? :last_quarter_moon:

Hi Lea,
Did you insert it in the custom code header, app level?
This is how it should look ( little button is created, see screenshot)

Found the issue: <https. < doesn’t have to be there (same at the end of the src")

<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>
<script>
  function addDarkmodeWidget() {
    new Darkmode().showWidget();
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>
1 Like

Thanks @matthieu_chateau !

Any way to disable it just on modals windows?

You could try this one:

<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>
<script>
  function addDarkmodeWidget() {
    if (window.location.href.indexOf('&viewMode=modal') === -1) {
      new Darkmode().showWidget();
    }
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>