如何重定向用户,如果他们有一个cookie javascript [英] How to redirect user if they have a cookie javascript
本文介绍了如何重定向用户,如果他们有一个cookie javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道在javascript中第一次访问该网页时如何为用户提供Cookie。然后,我需要cookie在1小时后过期,如果cookie仍然存在,并且他们在1小时之前尝试访问该页面,它将重定向它们。
I need to know how to give the user a cookie when they visit the page for the first time in javascript. Then i need the cookie to expire in 1 hour and it to redirect them if the cookie still exists and they try to access the page before 1 hour is up.
推荐答案
如果可以使用Jquery,您可以使用Jquery插件
if it is ok to use Jquery you can use the Jquery plugin
设置cookie
$.cookie("example", "foo", { path: '/', expires: 7 });
取得Cookie
alert( $.cookie("example") );
删除cookie
$.cookie("example", null);
使用它在javascript中编写重定向的自定义逻辑
Using this you write your custom logic for redirection in javascript
这篇关于如何重定向用户,如果他们有一个cookie javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文