setinterval

.setinterval and XSS

懵懂的女人 提交于 2020-07-18 17:12:04
问题 In the OWASP XSS prevention cheat sheet it says that untrusted data cannot be safely put inside the .setinterval JS function. Even if escaped/encoded, XSS is still possible. But if I have something like this: setInterval(function(){ alert('<%=UNTRUSTED_DATA%>'); }, 3000); And if I JS encode "UNTRUSTED_DATA", how would XSS be possible? 回答1: There is an overload of setInterval that accepts a string of code instead of a function, which is basically exec on an interval. I believe that is what the

Is it true that if possible I should never use setInterval & setTimeout?

天涯浪子 提交于 2020-07-17 08:18:20
问题 I am learning to code in JavaScript. I am programming something with some timed mouse animation. I'm just about to add some code which draws the mouse path. It's going to be something that takes the mousemove event, and every time the mouse moves draw a new line path on Canvas. And with time, that path is going to be more transparent until it disappears. Of course, new paths are always going to be opaque so there's a continuous movement. I figured out a way I can do this with just

Does Web Worker throttles setTimeout() / setInteval()?

拟墨画扇 提交于 2020-06-29 04:28:29
问题 I have a script on foreground tab that starts (dedicated) web worker. Now I see that setTimeout(xxx, 100) in that web worker is limited to be triggered not more often than once per second instead of 10 times per second as required. I've googled such a limitation for inactive tabs but are there any docs that say the same about Web Workers? I've checked this in Chrome and Firefox. 回答1: There is no real specs about that throttling behavior, even though they do allow it: Optionally, wait a

Does Web Worker throttles setTimeout() / setInteval()?

孤街醉人 提交于 2020-06-29 04:28:07
问题 I have a script on foreground tab that starts (dedicated) web worker. Now I see that setTimeout(xxx, 100) in that web worker is limited to be triggered not more often than once per second instead of 10 times per second as required. I've googled such a limitation for inactive tabs but are there any docs that say the same about Web Workers? I've checked this in Chrome and Firefox. 回答1: There is no real specs about that throttling behavior, even though they do allow it: Optionally, wait a

How to return a Promise with setInterval()

陌路散爱 提交于 2020-05-28 11:51:09
问题 I am trying to return a Promise object ever 1000ms, but i am not sure how to access the data returned in the Promise when it is inside a setInterval() callback. EDIT I appears i was not being very clear as to my intentions, so i will try and explain what it is i am trying to do. I making a count down where by the necessary calculations are are don every 1000ms based on specified end date. Here is the code that provides the return value i would like returned as a Pormise value every 1000ms:

Closure counter inside setInterval

血红的双手。 提交于 2020-05-13 07:10:29
问题 I have a function: setInterval(function () { var counter = 0; (function() { counter = counter + 1; console.log(counter); })(counter) }, 1000) Why does not it increment the counter? (instead, it logs 1's). How to make it log ascending numbers? (1, 2, 3, ....) 回答1: You are passing an argument to your anonymous function, but you aren't assigning that argument to a variable. You forgot to put the arguments in the function definition. You are creating new variables with every iteration instead of

Closure counter inside setInterval

主宰稳场 提交于 2020-05-13 07:09:55
问题 I have a function: setInterval(function () { var counter = 0; (function() { counter = counter + 1; console.log(counter); })(counter) }, 1000) Why does not it increment the counter? (instead, it logs 1's). How to make it log ascending numbers? (1, 2, 3, ....) 回答1: You are passing an argument to your anonymous function, but you aren't assigning that argument to a variable. You forgot to put the arguments in the function definition. You are creating new variables with every iteration instead of

clearInterval doesn't clearInterval

扶醉桌前 提交于 2020-04-30 16:32:15
问题 var timer; function check_element_load(){ timer = window.setInterval(function(){ console.log("still working"); // keeps running forever if(document.getElementById("comments")){ console.log("FOUND"); // this actually runs document.getElementsByTagName("fb:comments")[0].setAttribute('order_by', 'social'); window.clearInterval(timer); // < not effective } }, 50); } check_element_load(); I'm trying to put a script on top to keep checking if a specific element was successfully loaded in the

停止JavaScript中的setInterval调用

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-06 13:53:14
问题: I am using setInterval(fname, 10000); 我正在使用 setInterval(fname, 10000); to call a function every 10 seconds in JavaScript. 在JavaScript中每10秒调用一次函数。 Is it possible to stop calling it on some event? 是否可以在某个事件中停止调用它? I want the user to be able to stop the repeated refresh of data. 我希望用户能够停止重复刷新数据。 解决方案: 参考一: https://stackoom.com/question/SNS/停止JavaScript中的setInterval调用 参考二: https://oldbug.net/q/SNS/Stop-setInterval-call-in-JavaScript 来源: oschina 链接: https://my.oschina.net/stackoom/blog/3220504

无缝滚动

て烟熏妆下的殇ゞ 提交于 2020-04-04 22:31:19
无缝滚动好像是互联网广告最大的一个载体,可以用“无处不在”来形容它。不过它比起早期的闪光字体,浮动广告算进步了。由于需求巨大,做前台迟早会遇到它。我先给出结构层部分,再慢慢讲解其实现原理。 01. < dl id = "marquee" > 02. < dt > 03. < img src = " http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s017.jpg " alt = "无缝滚动" /> 04. < img src = " http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg " alt = "无缝滚动" /> 05. < img src = " http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg " alt = "无缝滚动" /> 06. < img src = " http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg " alt = "无缝滚动" /> 07. < img src = " http://images.cnblogs.com/cnblogs_com