[英]Add URl to cookie and redirect to URL on return
我需要检查是否存在 cookie 以便让用户继续他们的旅程,如果不是,他们点击一个按钮(然后设置 cookie)并将它们发送给第三方以在返回之前注册一些详细信息。
我可以设置并检查 cookie,但我想将页面 url 添加到 cookie 中,当用户从第三方站点返回时,cookie 中的 url 被拾取,并将它们重定向到他们离开的页面. (希望一切都有意义)。
到目前为止的代码...
//Check for cookie
if (document.cookie.indexOf("LostForWordsSession=Valid") == -1) {
$('.poster-image').show(); // This is a button that's shown if the cookie isn't present
}
// Button code
var url = window.location.href;
$(".poster-image").click(function(){
document.cookie = "LostForWordsSession=Valid; path=url";
window.location.replace("off to another site to register");
});
一旦用户注册,他们将被转发到我网站上的一个通用页面,我想从那里重定向他们(还没有代码,因为我有点难住了)。
任何帮助真的很感激! 并提前致谢 =)
这听起来像是 sessionStorage 的工作:
// I assume you want to go to the old URL?
// this code needs to be in all pages you can return to from rd party
const url = window.location.href;
const session = sessionStorage.getItem("LostForWordsSessionUrl");
if (session && session != url) location.replace(session);
else session = false;
$('.poster-image').toggle(!session); // show if no session
$(".poster-image").on("click",function(){
sessionStorage.setItem("LostForWordsSessionUrl",url)
window.location.replace("off to another site to register");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.