我想在某些情况下将用户发送到“登陆”页面,例如,重定向到新页面但记住原始位置
if (condition) {
window.location = "http://mywebsite.com/landingpage"
}
,但我也想记住一个用户被导航到,这样我可以将其移动用户到原来的目的地的着陆页上,再重定向链接的原始目标。
我知道如何用PHP做到这一点,但我完全需要JS/jQuery。我可以使用cookies,如果这样做更容易。
我在想,也许是这样的:
// 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 – Zword