LocationBack_wev8.js
2.14 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
if(typeof(Mobile_NS) == 'undefined'){
Mobile_NS = {};
}
Mobile_NS.LocationBack = function(){
this.cookieName = "Mobile_Locations";
};
Mobile_NS.LocationBack.prototype.writeLocationInCookie = function(){
var l = Mobile_NS_ReadCookie(this.cookieName);
if(!l){
l = location.href;
}else{
l += "|" + location.href;
}
Mobile_NS_WriteCookie(this.cookieName, l);
};
Mobile_NS.LocationBack.prototype.getBackLocation = function(){
var l = Mobile_NS_ReadCookie(this.cookieName);
if(!l){
return "";
}
var url = "";
var lArr = l.split("|");
if(lArr.length > 1){
url = lArr[lArr.length - 2];
lArr.pop();
lArr.pop();
}else{
lArr.pop();
}
var newL = "";
for(var i = 0; i < lArr.length; i++){
newL += lArr[i];
if(i != (lArr.length - 1)){
newL += "|";
}
}
Mobile_NS_WriteCookie(this.cookieName, newL);
return url;
};
Mobile_NS.LocationBack.prototype.doLocationBack = function(){
var l = this.getBackLocation();
if(l == ""){
return "BACK";
}else{
location.href = l;
return "1";
}
};
Mobile_NS.LocationBack.prototype.removeLastLocation = function(){
var l = Mobile_NS_ReadCookie(this.cookieName);
if(!l){
return;
}
var lArr = l.split("|");
lArr.pop();
var newL = "";
for(var i = 0; i < lArr.length; i++){
newL += lArr[i];
if(i != (lArr.length - 1)){
newL += "|";
}
}
Mobile_NS_WriteCookie(this.cookieName, newL);
};
Mobile_NS.LocationBack.prototype.clearLocation = function(){
Mobile_NS_DelCookie(this.cookieName);
};
//写cookie
function Mobile_NS_WriteCookie(name, value){
document.cookie = name + "="+ escape (value);
};
//读cookie
function Mobile_NS_ReadCookie(name){
var b = document.cookie;
var e = name + "=";
var d = b.indexOf("; " + e);
if (d == -1) {
d = b.indexOf(e);
if (d != 0) {
return null;
}
} else {
d += 2
}
var a = document.cookie.indexOf(";", d);
if (a == -1) {
a = b.length
}
return unescape(b.substring(d + e.length, a))
};
//删除cookie
function Mobile_NS_DelCookie(name){
var date = new Date();
date.setTime(date.getTime() - 10000);
document.cookie = name + "=a; expires=" + date.toGMTString();
};