在chrome控制台中重新加载后保持Javascript迭代 [英] Keep the Javascript Iteration after reload in chrome console

查看:117
本文介绍了在chrome控制台中重新加载后保持Javascript迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行迭代,并且在迭代中的代码最后一个代码中我放了一个代码来重新加载页面。

I'm doing iteration, and in code last code in the iteration i put a code that will reload the page.

如何在重新加载后继续运行JavaScript迭代并继续状态?

How to keep the JavaScript iteration running after reload and continue the state ?

例如

for(i=0;i<5;i++) {
    document.reload();
}

运行上面的代码后,代码停止并重新加载控制台。

After running above code, the code stopped and the console reloaded .

上面的代码可能不起作用,但我希望它解释我正在尝试做什么。

The code above might not work, but i wish it explain what i'm trying to do .

推荐答案

您需要将状态存储在未重置的位置。 localStorage 是理想的解决方案。

You need to store the state in a place where it's not reset. localStorage is the ideal solution.

var i = parseInt(localStorage['i'])||0;
localStorage['i'] = i+1;
// do some stuff
// and reload if you want

这篇关于在chrome控制台中重新加载后保持Javascript迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆