开发者

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开发者_Python百科 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);
}


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();
});


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.


try this

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

setTimeout:

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


For me Varriotts answer didn't work ... the only way I could get setTimeout working on the Android phone i used for testing (running v 2.something) is by the following notation:

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

This looks weird, passing just the name of a function, but after hours of trying around, it was the only way it worked.


I tried this and it solved my problem.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜