settimeout

Chrome extension setTimeout not working properly

别说谁变了你拦得住时间么 提交于 2019-12-18 15:48:24
问题 My first post here =]. I'm building a chrome extension and I'm using a setTimeout recursively. I noticed that if I set it to up to 13secs, it works, but if I set it to 14secs+ it won't work. This is an example which is on my background.js function start() { var timeout = setTimeout( function() { start(); }, 1000*15); alert('test'); } chrome.webNavigation.onCompleted.addListener(function(o) { start(); }, { url: [ {urlContains: 'http://www.example.com/in.php'}, {urlContains: 'http://www.example

以setTimeout来聊聊Event Loop

夙愿已清 提交于 2019-12-18 15:16:16
终于到了神话破灭的时刻…… 这注定是一篇“自取其辱”的博客,飞哥,你们眼中的大神,Duang,这次脸朝下摔地上了。 故事得从这个求助开始: e.returnValue 报错:未定义 ,“一起帮”现在人气还不够旺,碰到了我勉勉强强能够解决的问题,硬着头皮也得上啊!远程一看,问题不是e.returnValue没值,是e本身就没值。而更核心的问题是:这段代码,是被放在setTimeout()里面的。 (这里插一句:很多问题,就得远程,求助人贴出来的代码,根本就没抓住重点。话说,很多时候,要是能抓住问题的核心,问题也已经解决了一大半了。) 把代码简单化一下,代码大致应该是这样的: 1 <script> 2 function showEvent(){ 3 setTimeout( 4 function(){ 5 alert('in setTimeout:'+ event); 6 },100 7 ); 8 } 9 </script> 10 11 <input type="submit" name="Submit" value="提交" onclick="showEvent()" /> 点击提交按钮,就会看到:event 为 undefined。 凭着直觉,真的就是坑踩得太多的直觉,我飞快的解决了这个问题:在setTimeout()之前加一行代码,如下所示: 1 function

jquery hover and setTimeout / clearTimeOut

99封情书 提交于 2019-12-18 12:07:27
问题 I'm currently trying to do a menu with submenu. Here is what i want to do. On hover a link (#mylink) i want to display a div (lets call it "#submenu") right under it. On mouse leave this link a want to execute a function after 5 second. In this interval of 5 seconds, if i hover my div (#submenu) i want to clearTimeout. So this div won't desapear after 5 seconds. Here is my code : $(document).ready(function() { $("#mylink").hover( function () { $('#submenu').show(); }, function() { var timer =

What causes “function is not defined” when passing a string to setTimeout?

若如初见. 提交于 2019-12-18 09:54:09
问题 var my_new_function = function(){ ---- }; window.setTimeout(my_new_function, 1600); the above works properly without any errors. when i use: window.setTimeout("my_new_function()", 1600); it's working properly, but firebug is showing error : my_new_function is not defined in some articles about setTimeout, i found calling functions like in the 1st method, and in some other articles, i saw the other method. which is more correct? and why is firebug showing such an error? 回答1: When you call the

setTimeout(callback) followed by while loop never fires

三世轮回 提交于 2019-12-18 09:22:27
问题 I have the following code below (note, I'll be adding more code into the loop later, but I need this to work first): var calls_on = true; function hunt(max, ext, duration){ if(duration != '0' || duration != false || duration != 0){ duration = duration * 1000; // milliseconds to delay before stopping calls var t=setTimeout(function(){calls_on=false;}, duration); } while(calls_on){ alert('reached'); } alert('test'); } I have confirmed that the 'duration' conditional is executing, and the

Node.js setTimeout for 24 hours - any caveats?

旧街凉风 提交于 2019-12-18 07:39:39
问题 Simple question, I want to set 24 or 12 hours timeout in Node.js to periodically (once or twice a day) check some db data and clean suspicious garbage, if any. Is there any possible problems or performance issues, caused by setting huge timeout, that i need to be aware of? I don't mind if it's not exact 12-24hr in ms, and don't mind loosing this timeout on server crash, as I will run same garbage collector on server startup anyway. Conclusion: I'm not using native OS cron to run separate

setTimeout not working on safari mobile

纵饮孤独 提交于 2019-12-18 07:37:07
问题 I have a function that shows a menu when clicking on it, and I want it to disappear after 5 seconds. This is my javascript - it works properly on desktop browser but it doesn't disappear on the mobile ones. $(function() { $('#prod_btn').click(function() { $(this).addClass('selected').next('ul').css('display', 'block'); setTimeout(hideMenu, 5000); }); }); function hideMenu() { $('#prod_btn').removeClass('selected').next('ul').css('display', 'none'); } Where is the problem? Thanks 回答1: I've

Using setTimeout to update progress bar when looping over multiple variables

我的未来我决定 提交于 2019-12-18 07:12:29
问题 Suppose you have 3 arrays you want to loop over, with lengths x, y, and z, and for each loop, you want to update a progress bar. For example: function run() { x = 100; y = 100; z = 10; count = 0; for (i=0; i<x; i++) { //some code for (j=0; j<y; j++) { // some code for (k=0; k<z; k++) { //some code $("#progressbar").reportprogress(100*++count/(x*y*z)); } } } } However, in this example, the progress bar doesn't update until the function completes. Therefore, I believe I need to use setTimeout

what is setTimeOut() function in javascript?

五迷三道 提交于 2019-12-18 07:04:29
问题 Can i ask what the function of setTimeOut method in javascript?As below: function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()',500); } 回答1: Not sure you what you want. setTimeout is a method of the global window object. It executes the given function (or evaluates the given

setTimeout inside while loop

狂风中的少年 提交于 2019-12-18 05:02:28
问题 I've searched for how to use setTimeOut with for loops, but there isn't a lot on how to use it with while loops, and I don't see why there should be much difference anyway. I've written a few variations of the following code, but this loop seems to crash the browser: while(src == '') { (function(){ setTimeout(function(){ src = $('#currentImage').val(); $("#img_"+imgIdx).attr('src',src); }, 500); }); } Why? Basically I have an image created dynamically whose source attribute takes time to load