我想在某些情況下將用戶發送到「登陸」頁面,例如,重定向到新頁面但記住原始位置
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