【发布时间】:2013-12-05 21:46:18
【问题描述】:
我想在某些条件下将用户引导到“登陆”页面,例如
if (condition) {
window.location = "http://mywebsite.com/landingpage"
}
但我还想记住用户导航到的原始目的地,以便我可以在着陆页上放置一个重定向链接,将用户移动到原始目的地。
我知道如何使用 PHP 来做到这一点,但我完全需要 JS/jQuery 来实现这一点。我可以使用 cookie,如果这能让事情变得更容易的话。
我在想,也许是这样的:
// Condition when user moves to the page
if (condition) {
// Set cookie with value of current page
$.cookie('locational_cookie', window.location, { expires: 1});
// Redirect
window.location = "http://mywebsite.com/landingpage";
}
// When on the landing page, change the href of the "back" link to the original URL that is in the cookie.
$(".landingpage a.back").attr("href", $.cookie('locational_cookie'));
【问题讨论】:
-
一种方法是将当前位置作为 GET 发送
标签: javascript php jquery redirect cookies