SetTimeout not being called in android webkit

On my Android phone (2.1), I observe strange behavior with setTimeout, when on the finger we press the touch screen for a while.

This very simple code actually works fine (1 call every second) until I scroll for a while (2-3 seconds is enough) when it stops being called

$(document).ready(function(){
    spam();
});

function spam(){
    console.log("cia")
    setTimeout(spam, 1000);
}
+3
source share
5 answers

I have the same problem.

The solution was for me to define the called function as a variable, than pass ist as a parameter to setTimeout.

Try the following:

var spam = function(){
   console.log("cia")
   setTimeout(spam, 1000);
}

$(document).ready(function(){
   spam();
});
+3
source

I had this problem on my device when I was doing some kind of development, but none of these solutions worked for me.

, , , , .

, , . , , , . , , .

: - , ( setTimeout(), setInterval() , javascript ).

Samsung Galaxy S Android 2.1, , - , , .

+1

try it

    function spam(){
        console.log("cia")
        setTimeout("spam()", 1000);
    }

SetTimeout:

    /**
    @param {String|Function} vCode
    @param {Number} iMillis
    @return Number
    */
    window.setTimeout = function(vCode,iMillis) {};
+1
source

For me, Varriotts answer did not work ... the only way to get setTimeout to work on the Android phone that I used for testing (works v 2.something) is the following notation:

function foo() {}
window.setTimeout(foo, 200);

It looks weird, passing only the name of the function, but after several hours of trying, it was the only way it worked.

0
source

I tried this and it solved my problem.

setTimout(function(){aFunction(text);}, 200);
0
source

Source: https://habr.com/ru/post/1759788/


All Articles