-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.html
56 lines (49 loc) · 2.22 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<html>
<head>
<script type="text/javascript" src="src/lib/jquery.js"></script>
<script type="text/javascript" src="src/limitedStorage.js"></script>
<script type="text/javascript" src="src/crossDomainStorage.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
/*
* Testing limited local storage
*/
lstorage = limitedStorage({maxItems: 20, prefix: '_testing_'});
//Note that the specified number of max items (20) are smaller
//than the number of keys to store in the following loop (100):
for (var i = 0; i<=100; i++) {
lstorage.setItem("key-" + i, {
'a_tag': 'a value - ' + i,
'other_tag':
'other value - ' + i
});
}
//There must be only the last 20 values
for (var i = 0; i<=100; i++) {
value = lstorage.getItem("key-"+i);
if(value !== null){
//you'll need a <div id="results"></div> in your test page...
document.getElementById('results').innerHTML += "<br/>found: key-" + i + ", value: " + JSON.stringify(value);
}
}
document.getElementById('results').innerHTML += "<br/>-----------------------<br/>";
/*
* Testing cross-domain storage
*/
cdstorage = crossDomainStorage({
origin: "http://localhost",
path: "/localStorage/crossd_iframe.html"
});
//Now we can use the object to set or get values from a shared localStorage space:
cdstorage.setItem('a_cross-domain_key', "The value should be a string, or it will be converted to string..");
//This will store the previous value asynchronously, so we need callbacks:
cdstorage.getItem('a_cross-domain_key', function(key, value) {
document.getElementById('results').innerHTML += "<br/>Cross Domain callback: (" + key + ": " + value + ")";
});
});
</script>
<div id="results"></div>
</body>
</html>