質問編集履歴

2

修正

2020/09/17 05:22

投稿

wing283
wing283

スコア123

test CHANGED
File without changes
test CHANGED
@@ -120,7 +120,7 @@
120
120
 
121
121
    if (+now > target_date) {
122
122
 
123
-    location.href = 'htp:next_page.html';
123
+    location.href = 'end.html';
124
124
 
125
125
    }
126
126
 

1

追記

2020/09/17 05:22

投稿

wing283
wing283

スコア123

test CHANGED
File without changes
test CHANGED
@@ -28,25 +28,43 @@
28
28
 
29
29
    throw new Error;
30
30
 
31
+  
32
+
31
33
   var cookie = [ encodeURIComponent (name) + '=' + encodeURIComponent (value) ];
32
34
 
35
+  
36
+
33
37
   if (expires)
34
38
 
35
39
     cookie[cookie.length] = 'expires=' + new Date (expires).toUTCString ();
36
40
 
41
+  
42
+
37
43
   if (path)
38
44
 
39
45
     cookie[cookie.length] = 'path=' + encodeURI (path);
40
46
 
47
+
48
+
41
49
   if (domain)
42
50
 
43
51
     cookie[cookie.length] = 'domain=' + encodeURI (domain);
44
52
 
53
+
54
+
45
55
   if (secure)
46
56
 
47
57
     cookie.push ('secure');
48
58
 
59
+
60
+
49
- doc.cookie = cookie.join ('; ');}
61
+ doc.cookie = cookie.join ('; ');
62
+
63
+ }
64
+
65
+
66
+
67
+
50
68
 
51
69
  function getCookie (doc, name) {
52
70
 
@@ -54,25 +72,67 @@
54
72
 
55
73
    throw new Error;
56
74
 
75
+
76
+
57
77
   var n = encodeURIComponent (name).replace (/\W/g, '\$&');
58
78
 
59
79
   var v = doc.cookie.match (new RegExp (n + '\s*=\s*(.*?)(?:[;,\s]|$)'));
60
80
 
81
+
82
+
61
-  return (v) ? decodeURIComponent (v[1]): '';}
83
+  return (v) ? decodeURIComponent (v[1]): '';
84
+
62
-
85
+ }
86
+
87
+
88
+
89
+
90
+
91
+ function addDay (dateObj, day) {
92
+
93
+  var date = new Date (dateObj);
94
+
63
- function addDay (dateObj, day) { var date = new Date (dateObj); date.setDate (date.getDate () + 365); return date;}
95
+  date.setDate (date.getDate () + day);
96
+
97
+  return date;
98
+
99
+ }
100
+
101
+
64
102
 
65
103
  var COKKIE_NAME = 'hoge';
66
104
 
67
105
  var target_date = getCookie (document, COKKIE_NAME);
68
106
 
107
+
108
+
109
+
110
+
69
111
  (function () {
70
112
 
71
113
   var now = new Date;
72
114
 
115
+
116
+
117
+  if (target_date) {
118
+
73
-  if (target_date) { target_date = Date.parse (target_date); if (+now > target_date) { location.href = 'end.html';}}
119
+   target_date = Date.parse (target_date);
120
+
74
-
121
+   if (+now > target_date) {
122
+
123
+    location.href = 'htp:next_page.html';
124
+
125
+   }
126
+
127
+  }
128
+
129
+  else { 
130
+
131
+   target_date = addDay (now, 1);
132
+
75
-  else { target_date = addDay (now, 1); setCookie (document, COKKIE_NAME, String (target_date), addDay (now, 1)); target_date = +target_date;}
133
+   setCookie (document, COKKIE_NAME, String (target_date), addDay (now, 100));
134
+
135
+  }
76
136
 
77
137
  }) ();
78
138
 
@@ -142,6 +202,12 @@
142
202
 
143
203
 
144
204
 
205
+ ■追記
206
+
207
+ カウントが0になった際にページ遷移せずにループしてしまいます。
208
+
209
+
210
+
145
211
  問題は以下の辺りだと思うのですが、わかりません...。
146
212
 
147
213