HTML5 on iPhone Safari - data stored by localStorage does not always persist. Why?
        Posted  
        
            by Aerodyne
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Aerodyne
        
        
        
        Published on 2010-04-14T20:18:57Z
        Indexed on 
            2010/05/19
            14:40 UTC
        
        
        Read the original article
        Hit count: 257
        
Hi,
I write a simple iPhone web app using HTML5's localStorage.
Tests on a 2G device show that data stored using localStorage does not persist after the Safari process is killed although the opened Safari windows are remembered.  
The data is also lost in a case where I am on a different site on a different Safari window, then I change the window to where the web app in subject is shown. When Safari loads the page it automatically refreshes the page. Then the data is lost. This is a simple test code:
<html>
<head>
    <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<script>
    alert("1:" + localStorage.getItem("test"));
    localStorage.setItem("test", "123");
    alert("2:" + localStorage.getItem("test"));
</script>
</body>
As far as I understand the data should persist!
Can anyone shed some light on this behavior? What should I do to get the persistence to work?  
Thanks!
Tom.
© Stack Overflow or respective owner