-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_index.js
78 lines (68 loc) · 1.78 KB
/
test_index.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var title = 'index.html';
var storage = (function() {
if (window.localStorage) {
//alert('localStorage supported');
} else if (Cookies){
//alert("Local storage is not supported, using Cookies");
} else {
alert('exception');
}
var key = 'event';
return {
setLocalData: function(msg) {
var oldVal = '';
if (window.localStorage) {
oldVal = localStorage.getItem(key) || '';
localStorage.setItem(key, oldVal + msg);
} else if (Cookies) {
oldVal = Cookies.get(key) || '';
Cookies.set(key, oldVal + msg);
}
},
getLocalData: function() {
if (window.localStorage) {
return localStorage.getItem(key) || '';
} else if (Cookies) {
return Cookies.get(key) || '';
}
},
removeLocalData: function() {
if (window.localStorage) {
localStorage.removeItem(key);
} else if (Cookies) {
Cookies.expire(key);
}
}
}
})();
window.onbeforeunload = function () {
storage.setLocalData("\nonbeforeunload index1111.html");
};
window.onunload = function () {
storage.setLocalData("\nonunload index1111.html");
};
var isIOS = !!navigator.platform.match(/iPhone|iPod|iPad/);
if (isIOS) {
alert('is iOS!');
window.onpagehide = function () {
storage.setLocalData("\nonpagehide index1111.html");
};
} else {
window.onpagehide = function () {
storage.setLocalData("\nonpagehide index1111.html (not iOS)");
};
}
window.onload = function() {
storage.setLocalData("\nonload index1111.html");
setInterval(showLog, 1000);
id('clearbtn').onclick = function() {
storage.removeLocalData();
showLog();
}
};
function id(str) {
return document.getElementById(str);
}
function showLog() {
id('log').value = storage.getLocalData() || '[empty]';
}