开发者

Set and clear html5 persistent data

开发者 https://www.devze.com 2023-04-04 01:36 出处:网络
Im working on using HTML5 persistent storage on an existing application used for the purpose of surveys.

Im working on using HTML5 persistent storage on an existing application used for the purpose of surveys.

What I need to now do, is pass a variable through to the final "completed" page, which I can then use to remove the persistant object that I have saved in the mobile devices memory.

Any ideas how I can do this?

Currently, the submit button is set up like this.

<input type='开发者_开发技巧submit' value='Submit' onclick="saveData(); surveyfunction();"/>

The saveData() function, is my function, (adds values to array then makes a unique object e.t.c, the surveyfunction is the survey softwares function for physically submitting the data.

Any ideas greatly appreciated - thanks!


Use localStorage.get/setItem. This worked when I tested it locally:

(test.html)

<script type="text/javascript">
localStorage.setItem('HelloWorld', 'Buongiorno, mundo!');
alert(localStorage.getItem('HelloWorld'));
window.location.href='test2.html';
</script>

(test2.html)

<script>
alert(localStorage.getItem('HelloWorld'));

</script>

You'll want to test for local storage support using Modernizr or something.

UPDATE:

what I need to do, is find somehow to call the saved object with a set key (the variable I will pass), dynamically from the success page, so that I know its ok to delete the item from the memory...

You can either persist it to a cookie or local storage. Local storage is probably preferable, but there's no reason you can't come up with a very detailed naming convention for it.

On the completed page, there is no way to obtain the SID of the completed survey.

Why can't you set the SID in a cookie? With cookies, you can set the path that the cookie is visible to as part of the cookie's configuration. That means if you have /survey1 and /servey2 on your server, you can set two separate cookies each with their own SID value.

0

精彩评论

暂无评论...
验证码 换一张
取 消