M
M
MentozZz ORG2021-09-19 10:50:24
JavaScript
MentozZz ORG, 2021-09-19 10:50:24

Why do I have a function running before the user clicks the button?

I have the enableDark() function running when the site is opened, even if the user did not click on the button to launch this function, but if you click on the button to disable this function disableDark(), then the function no longer starts itself when the page is refreshed (that is, it works as it should while saving data in local storage)

here is the code for local storage

<!-- var _acic= {dataProvider:10};(function(){var e=document.createElement ("script");e.type="text/javascript";e.async=true;e.src="//www.acint.net/aci.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}) () //--> </script> <script> function disableDark() { DarkReader.disable (); localStorage.setItem('bgcolor', 1); } function enableDark() { localStorage.setItem('bgcolor', 0); DarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 }); } if (localStorage.getItem('bgcolor') == 1) enableDark(); else disableDark(); </script>


here is js
<script src="https://онлайн.net/black/dark.js"></script>


here is the html switches
<i class="fa-solid fa-lightbulb-on theme-i getdark" onclick=disableDark()  aria-hidden="true"></i><i onclick=enableDark() class="fa-solid fa-lightbulb-slash theme-i getlight"></i>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
low molecular macro, 2021-09-19
@molekulyarniy

See how the listener is hung up here

A
alekssamos, 2021-09-19
@alekssamos

window.addEventListener("load", function(){
    if (localStorage.getItem('bgcolor') == 1) enableDark(); else disableDark();
});

S
Sergey Romanov, 2014-09-26
@Rattlesneyk

SELECT al.*, ar.* 
     FROM albums AS al
LEFT JOIN artists AS ar ON ar.id = al.artist_id
    WHERE ar.aName LIKE '%...%'
       OR al.aName LIKE '%...%'

This query is suitable if there are not many records in the database. If there are a lot of records (about more than 100,000), and in the condition you have a check on the values ​​in 2 tables, then you can do this. But keep in mind that on small tables this does not make sense.
SELECT al.*, ar.* 
     FROM albums AS al
    WHERE al.aName LIKE '%...%'
      AND al.id IN (
         SELECT ar.id 
           FROM artists AS ar 
          WHERE ar.aName LIKE '%...%' )

This query also results in one less condition.

V
Volodymyr Godyak, 2014-09-27
@wmgodyak

select a.id,a.aName as albums_name,s.id as artist_id,s.aName as artist_name
from albums a
join artists s on s.aId = a.aArtist and s.aName like '%$s%'
where a.aName like '%$s%'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question