将已接受条款的用户重定向到其他网页(Cookie或localStorage) [英] Redirect users who already accepted terms to another webpage (cookies or localStorage)

查看:678
本文介绍了将已接受条款的用户重定向到其他网页(Cookie或localStorage)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了网站的移动版本。在用户看到一个特定的页面之前,他必须按下一个按钮 - 确认,这基本上确认他接受我们网站的条款。此外,一旦用户按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.

演示:

http://jsfiddle.net/AbdiasSoftware/wk9bS/

当然,您需要检查 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆