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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With