admin管理员组文章数量:1360351
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);
}
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);
}
Share
Improve this question
edited Apr 26, 2012 at 9:08
Sergey Glotov
20.4k11 gold badges86 silver badges99 bronze badges
asked Aug 15, 2010 at 18:55
Fabio FornoFabio Forno
311 gold badge2 silver badges4 bronze badges
1
- 3 Interesting observation. What specifically is the question though? Are you looking for an explanation? A workaround? – Mark Byers Commented Aug 15, 2010 at 18:58
5 Answers
Reset to default 3I 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);
本文标签: javascriptsetTimeout not called in android webkitStack Overflow
版权声明:本文标题:javascript - setTimeout not called in android webkit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743895045a2557628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论