Response.redirect杀死本地存储? [英] Response.redirect kills local storage?

查看:67
本文介绍了Response.redirect杀死本地存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ASP中的 HTML5 本地存储.我可以读写存储,但是如果我执行 response.redirect ,整个本地存储都被清除了吗?

I am trying to work with HTML5 local storage in asp. I can read and write to the storage, but if I do a response.redirect the entire local storage is wiped out?

<script type='text/javascript'>

localStorage["email"] = "<%=email%>";

localStorage["remember"] = "1";
</script>

这对于保存工作正常,我可以使用开发人员工具查看保存在本地存储中的变量.

This works fine for saving and I can see the variable saved in local storage using Developer Tools.

但是,在那之后我添加

 response.redirect ("index.asp")

然后清理整个本地存储.我该如何坚持下去?

then the entire local storage is cleaned. How can I cause to to persist?

推荐答案

问题是(正如Neil所建议的)localStorage需要花费几毫秒的时间来执行,并且您需要在过程完成之前进行重定向.在localStorage中设置某些内容后,我对javascript重定向也遇到了类似的问题.您正在使用ASP,所以(我不能肯定地说不看更多代码),但是如果我没记错的话,服务器上已经对ASP进行了解析,因此您可以在执行 any javascript之前进行重定向.

The problem is (as Neil suggests) that localStorage takes a few milliseconds to execute and that you're redirecting before the process is complete. I had a similar problem with a javascript redirect after setting something in localStorage. You're using ASP so (and I can't say for sure without seeing more of the code) but if I remember correctly ASP is parsed on the Server so you're redirecting before any javascript executes.

尝试使用此代替:

<script type='text/javascript'>

localStorage["email"] = "<%=email%>";

localStorage["remember"] = "1";

setTimeout(function(){
   location.href = "index.asp";
},100)

这篇关于Response.redirect杀死本地存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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