settimeout

jQuery: Fire mousemove events less often

给你一囗甜甜゛ 提交于 2019-12-20 15:23:25
问题 I'm trying to figure out a clean way to aggregate mousemove events so that I ensure my code gets called, but only once every 250-300 milliseconds. I've thought about using something like the following, but was wondering if there was a better pattern, or something jQuery provides that will do the same thing: var mousemove_timeout = null; $('body').mousemove(function() { if (mousemove_timeout == null) { mousemove_timeout = window.setTimeout(myFunction, 250); } }); function myFunction() { /* *

How to make a jquery function call after “X” seconds

戏子无情 提交于 2019-12-20 09:59:53
问题 I have a jquery function and I need to call it after opening the website in an Iframe. I am trying to open a weblink in an Iframe and after opening it I need to call the below function. So how do I do that? Here is my function: <script type="text/javascript"> $(document).ready(function(){ $("#<%=Button1.ClientID%>").click(function (event) { $('#<%=TextBox1.ClientID%>').change(function () { $('#various3').attr('href', $(this).val()); }); $("#<%=Button2.ClientID%>").click(); }); }) function

Prevent Socket IO from ping timeout on inactive or not focused browser page on Chrome, firefox & Safari mobile browsers

怎甘沉沦 提交于 2019-12-20 06:47:15
问题 I have a simple chat app using socket io. Very similar to the socket io chat official demo. Socket io goes to ping timeout on all mobile browsers whenever the user minimizes the page or opens another app or page gets out of foucs. In my web app whenever, the user clicks on file input upload from their chrome/firefox/safari browser on mobile, it opens up the phone dialog box to select the file from galley to select and upload. During this time (my chat page gets out of focus due to visibility)

JavaScript: setTimeout doesn't pause the loop

我只是一个虾纸丫 提交于 2019-12-20 05:22:07
问题 I need to make some delays in my loop, every time after some amount of data (after a few cycles/iterations through my loop) is sent to the server. Sending data and receiving respond from the server works fine, but requested delays in loop still don't work. Thanks a lot for your help. EDIT: Code was changed, please check the third answer (mine). <!DOCTYPE html> <html> <body> <h2>AJAX</h2> <button type="button" onclick="loadDoc()">Request data</button> <p id="demo"></p> <script> function

Firefox setTimeout(func, ms) sending default parameters to callback

我与影子孤独终老i 提交于 2019-12-20 03:43:21
问题 I am unable to find out more about this default parameter that I ran across and was hoping that someone could point out an explanation. In Firefox (3.6 in this case) if you call the following code: function test(someVar) { console.log('test ' + someVar); } setTimeout(test, 0); It will log a "random" number to the console. I know you can pass parameters in Firefox like so: setTimeout(test, 0, param1, param2); But it appears as though Firefox is automatically sending a value. I think it's the

By using javascript recursive setTimeout function, is it risky to get the stackoverflow? [duplicate]

南楼画角 提交于 2019-12-20 02:42:49
问题 This question already has answers here : how does setTimeout prevent potential stackoverflow (2 answers) Why the function called by setTimeout has no callstack limit? (2 answers) Closed last year . By using javascript recursive setTimeout function, is it risky to get the stackoverflow? By trying this example you can see in browser console that the stack grows. Why is it so? var iteration = 0; function bar() { iteration++; console.log("iteration: " + iteration); console.trace(); if(iteration <

JavaScript执行机制

喜夏-厌秋 提交于 2019-12-20 02:42:39
原文   简书原文:https://www.jianshu.com/p/0d2d42fbe1dc 大纲   1、场景分析   2、执行机制相关知识点   3、以实例来说明JavaScript的执行机制   4、相关概念 1、场景分析 /* 以下这段代码的执行结果是什么? 如果依照:js是按照语句出现的顺序执行这个理念, 那么代码执行的结果应该是: //"定时器开始啦" //"马上执行for循环啦" //"执行then函数啦" //"代码执行结束" 但结果并不是这样的,得到的结果是: //"马上执行for循环啦" //"代码执行结束" //"执行then函数啦" //"定时器开始啦" */ setTimeout(function(){ console.log('定时器开始啦') }); new Promise(function(resolve){ console.log('马上执行for循环啦'); for(var i = 0; i < 10000; i++){ i == 99 && resolve(); } }).then(function(){ console.log('执行then函数啦') }); console.log('代码执行结束'); 2、执行机制相关知识点 2.1、关于javascript   javascript是一门单线程语言,在最新的HTML5中提出了Web

By using javascript recursive setTimeout function, is it risky to get the stackoverflow? [duplicate]

十年热恋 提交于 2019-12-20 02:42:18
问题 This question already has answers here : how does setTimeout prevent potential stackoverflow (2 answers) Why the function called by setTimeout has no callstack limit? (2 answers) Closed last year . By using javascript recursive setTimeout function, is it risky to get the stackoverflow? By trying this example you can see in browser console that the stack grows. Why is it so? var iteration = 0; function bar() { iteration++; console.log("iteration: " + iteration); console.trace(); if(iteration <

Question about setTimeout that I need answer to

最后都变了- 提交于 2019-12-20 02:06:13
问题 So we all know setTimeout waits a certain amount of time before executing something. My question is, does it wait for the above code to finish executing first, before waiting a second to execute something else, or does it just wait for a second, and whether or not the above code has finished executing, it executes the rest of the code anyways? if (1 == 1) { //huge chunk of code } //end of if (1 == 1) var theTime = 1000; var timeout = setTimeout("location.reload(true);", theTime); function

How to pass parameters to setTimeout function

北城以北 提交于 2019-12-19 18:12:31
问题 I am relatively novice to javascript. I have written a simple counter program that starts count down from 10 till it reaches 1. <script type="text/javascript"> function countDown(secs) { var element = document.getElementById("status"); element.innerHTML = "Please wait for "+secs+" seconds"; if(secs < 1) { clearTimeout(timer); element.innerHTML = '<h2>Countdown Complete!</h2>'; element.innerHTML += '<a href="#">Click here now</a>'; } secs--; ---> **var timer = setTimeout('countDown('secs')'