问题描述
我制作了网站的移动版本。在用户看到一个特定的页面之前,他必须按下一个按钮 - 确认,这基本上确认他接受我们网站的条款。此外,一旦用户按CONFIRM按钮,他将被重定向到特定的页面。
I ve made a mobile version of a website. Before the user see a specific page he must press a button - CONFIRM, which basically confirms that he accepts the terms of our website. Moreover, as soon as the user press the CONFIRM button he is being redirected to the specific page.
我的问题是如何使用cookies或localStorage为了将已经接受条款的用户重定向到特定网页?
My question is how is it possible to use cookies or localStorage in order to redirect the users who already had been accepted the terms to the specific web page?
我不是很熟悉编程,所以请好好:)
I am not quite programming savvy so please be nice :)
推荐答案
您可以这样检查:
if (localStorage.getItem('accepted') === '1') {
//redirect - already accepted;
}
// after clicking accept
if (accepted === true) {
localStorage.setItem('accepted', '1');
//redirect
}
请注意,检查和设置必须
Note that the check and set must be in the same origin.
演示:
当然,您需要检查 localStorage
可用(隐式IMO),并提供后备机制,例如持久性Cookie:
Of course, you'll need to check that localStorage
is available (implicit IMO) and provide a fallback mechanism such as persistent cookies:
if (!!window.localStorage) {
//use code above
} else {
//use fallback
}
这篇关于将已接受条款的用户重定向到其他网页(Cookie或localStorage)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!