我尝试设置以下用户流程:
对于Cookie,我使用此插件:https://github.com/carhartl/jquery-cookie
这是HTML:
<a href="http://maccy.local:5757/core-connection-1">
<span class="thumb">
<img width="150" height="150" src="http://maccy.local:5757/wp-content/uploads/2014/06/400x400.jpeg" class="attachment-thumbnail wp-post-image" alt="400x400">
</span>
</a>
<a class="save-textbook-cc1" href="#">Save this as my book</a>
<a href="http://maccy.local:5757/core-connection-2">
<span class="thumb">
<img width="150" height="150" src="http://maccy.local:5757/wp-content/uploads/2014/06/400x400.jpeg" class="attachment-thumbnail wp-post-image" alt="400x400">
</span>
</a>
<a class="save-textbook-cc2" href="#">Save this as my book</a>
以下是我使用的jQuery,当然它不起作用:
$(function() {
var COOKIE_NAME = 'textbook-cookie'; /* create cookie */
var VISITED = 'visited' /* track where user has landed */
$( ".save-textbook-cc1" ).click(function() {
$.cookie(COOKIE_NAME, 'cc1', { expires: 7, path: '/index.php' });
alert("Textbook Saved as CC1!")
$.cookie(VISITED, 'no', { expires: 7, path: '/index.php' });
});
$( ".save-textbook-cc2" ).click(function() {
$.cookie(COOKIE_NAME, 'cc2', { expires: 7, path: '/index.php' });
alert("Textbook Saved as CC2!")
$.cookie(VISITED, 'no', { expires: 7, path: '/index.php' });
});
$go = $.cookie(COOKIE_NAME);
$visited = $.cookie(VISITED);
if ($go == 'cc1' ) AND ($visited == 'no') {
window.location = "/core-connection-1";
$.cookie(VISITED, 'yes', { expires: 7, path: '/index.php' });
}
elseif ($go == 'cc2' ) AND ($visited == 'no') {
window.location = "/core-connection-2";
$.cookie(VISITED, 'yes', { expires: 7, path: '/index.php' }); {
}
else {
}
});
答案 0 :(得分:0)
为什么不用PHP做这个?
查看PHP.net如何使用PHP设置cookie: http://www.php.net/manual/en/function.setcookie.php 或者在W3Schools上 http://www.w3schools.com/php/php_cookies.asp
P.S。如果你真的想用javascript做这个,请详细说明“它不工作”-bit请:)