Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.redirect kills local storage?

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.

However if after that I add

 response.redirect ("index.asp")

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

like image 452
user1480192 Avatar asked Sep 19 '12 07:09

user1480192


1 Answers

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.

Try using this instead:

<script type='text/javascript'>

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

localStorage["remember"] = "1";

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

like image 144
cgarvey Avatar answered Sep 20 '22 23:09

cgarvey