Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout not called in android webkit

On my android phone (2.1) I'm seeing a strange behavior with setTimeout when keeping a finger pressed on the touchscreen for a while.

This very simple code in fact works fine (1 call each second), until I scroll for a while the window (2-3 seconds are sufficient), when it stops being called

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

function spam(){
    console.log("cia")
    setTimeout(spam, 1000);
}
like image 744
Fabio Forno Avatar asked Sep 21 '26 13:09

Fabio Forno


2 Answers

I has the same Problem.

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

Try this:

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

$(document).ready(function(){
   spam();
});
like image 60
Varriott Avatar answered Sep 24 '26 03:09

Varriott


I had this issue before on my device when doing some development but neither of these solutions worked for me.

From the reading I did it's reasonably well documented that this does happens but seems to be no consistent way of resolving it.

What worked for me was closing the window I had my test site up down, clearing the cache, exiting the browser then opening task manager and shutting down the process. When I opened my browser again and went to my test site the standard code I had originally started working again.

My only guess is that the browser itself get's itself into some weird state where it doesn't run standard inbuilt browser functions (neither setTimeout() or setInterval() worked for me but both the javascript functions did exist).

I was testing with a Samsung Galaxy S running Android 2.1, I don't know if this will help anyone else but it's what worked for me.

like image 44
MDo Avatar answered Sep 24 '26 03:09

MDo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!