admin管理员组文章数量:1393071
I put a code will reload the current page in chrome console.
eg..
(function myLoop (i) {
setTimeout(function () {
console.log(i);
if (--i) myLoop(i);
}, 3000)
})(10);
After running above code, the loop runs only one time and the console reloaded.
how can i do this?
I put a code will reload the current page in chrome console.
eg..
(function myLoop (i) {
setTimeout(function () {
console.log(i);
if (--i) myLoop(i);
}, 3000)
})(10);
After running above code, the loop runs only one time and the console reloaded.
how can i do this?
Share Improve this question asked Jul 17, 2016 at 10:51 yolohoamyolohoam 312 silver badges7 bronze badges 2- Check this answer: stackoverflow./questions/26380086/… – KooiInc Commented Jul 17, 2016 at 11:35
- 1 what exactly are you trying to achieve? seems like localStorage should do the trick – mylee Commented Jul 17, 2016 at 11:36
3 Answers
Reset to default 4The function you provided counts down from 10 to 1, with a 3 second interval. If you are running that directly in the Chrome Console and you refresh your page in the middle, it will of course be killed because the function is executing in the context of the current page you have loaded.
If you want to persist the loop between reloads when the code is running within the page (not the console), then you could maintain the state of the variable when you are executing the code, e.g. in local storage or a cookie. When the page loads, use the stored value instead of the default.
Example:
window.onload = function() {
var count = localStorage.getItem('count');
if (count == null) count = 10;
(function myLoop(i) {
setTimeout(function() {
localStorage.setItem('count', (i-1));
console.log(i);
if (--i) {
myLoop(i);
} else {
localStorage.removeItem('count');
}
}, 3000)
})(count);
}
You may create a chrome extension, it can keep executing after reload
As first, why do you want to do this? It would be very weird you want to reload a webpage, why? If it is used for internet speed purposes i would prefer:
cmd.exe /C ping (target) /t 00 /n 65000
But you can try to use a loop statement for it. I'm not so familiar with C#, so i searched it up on internet.
int number = 0;
while(number < 5)
{
// yourcode
number = number + 1;
}
本文标签: javascriptHow to keep the loop after reload in chrome consoleStack Overflow
版权声明:本文标题:javascript - How to keep the loop after reload in chrome console? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744690836a2619985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论