v2.5.2
Giriş yap

Javascript Function setInterval ile çalışmıyor [ÇÖZÜLDÜ]

arduinoturkbatu
251 defa görüntülendi ve 1 kişi tarafından değerlendirildi

Electron ile bir uygulama oluşturuyorum. JS kodlarının çalışması gerekiyor ama setInterval(onLoading,500); çalışmıyor. İşte index.html ile bağlantılı benim script.js dosyam:

//...
setInterval(onLoading,500);

function onLoading() {
    console.log("Call: onLoading");
    var webview = activeTab.querySelector(".pageOuther webview");
    
    document.querySelector(".pageOuther .options span").innerText = webview.getTitle();

    webview.addEventListener('did-start-loading', function () {
        indicator.classList.add("load");
        idocument.querySelector(".pageOuther .options span").innerText = "Loading...";
    })
    webview.addEventListener('did-stop-loading', function () {
            activeTab.querySelector(".pageOuther .options span").innerText = webview.getTitle();
            console.log("onLoading: webview functions");
    })
    webview.addEventListener('page-title-updated', function () {
            document.querySelector(".pageOuther .options span").innerText = webview.getTitle();
            console.log("onLoading: webview functions");
    })
    webview.addEventListener('dom-ready', function () {
        webview.insertCSS(`
            input,proggress,progress{
                accent-color: #98E2C6 !important;
            }
        `)
    })

    if(webview.canGoBack()) {
        document.querySelector("#goback").setAttribute("data-clickable","true");
        document.querySelector("#goback").removeAttribute("disabled");
    }else {
        document.querySelector("#goback").setAttribute("data-clickable","false");
        document.querySelector("#goback").setAttribute("disabled","");
    }

    if(webview.canGoForward()) {
        document.querySelector("#goforward").setAttribute("data-clickable","true");
        document.querySelector("#goforward").removeAttribute("disabled");
    }else {
        document.querySelector("#goforward").setAttribute("data-clickable","false");
        document.querySelector("#goforward").setAttribute("disabled","");
    }

    webview.addEventListener('page-favicon-updated', e => {
        console.log(e.favicons);

        let activeTrigger = document.querySelector('[aria-selected="true"]');
        activeTrigger.style.backgroundImage = "url(" + e.favicons[e.favicons.length - 1] + ")";
    })
}
//...

Not: Bazı değişkenleri eklemeyi unuttuysam, onlarla uğraşmayın. Gerçek kod dosyasının başlangıcında bulunuyorlar.

setInterval'i Console ile çalıştırdığımda, gayet iyi çalışıyor ama başlangıçta çalışmasını istiyorum.

Sorun nasıl çözülebilir?

Cevap yaz
Cevaplar (1)
arduinoturkbatu
353 gün önce
<script>
    setInterval(onLoading,500);
</script>

Bu kodu html dosyama ekledim ve sorun çözüldü!