Redirect 如果未首先访问a.html页面,则从b.html页面重定向

Redirect 如果未首先访问a.html页面,则从b.html页面重定向,redirect,Redirect,如果某人以前没有访问过页面A.html,如何从页面B.html重定向 如果访问了页面A.html,则允许打开并B.html 所有页面都是html5当访问者转到a.html时设置cookie。当访问者导航到b.html时,检查cookie是否已设置,如果未设置,则启动重定向 所有这些都可以使用Javascript/jQuery/HTML实现 jQuery cookie库: 在JavaScript中重定向: 密码 在a.html和b.html上都包含jQuery和jQuery cookie插件。确保

如果某人以前没有访问过页面
A.html
,如何从页面
B.html
重定向

如果访问了页面
A.html
,则允许打开并
B.html


所有页面都是html5

当访问者转到a.html时设置cookie。当访问者导航到b.html时,检查cookie是否已设置,如果未设置,则启动重定向

所有这些都可以使用Javascript/jQuery/HTML实现

jQuery cookie库:

在JavaScript中重定向:

密码 在a.html和b.html上都包含jQuery和jQuery cookie插件。确保从上面链接的github repo下载jquery.cookie.js文件的副本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.cookie.js"></script>

在page a.html上,当访问者加载页面时,使用以下代码片段设置cookie:

<script>
    $.cookie('page_a_visited', 'true', { expires: 7, path: '/' });
</script>

$.cookie('page_a_visted','true',{expires:7,path:'/'});
在第b.html页添加此代码段以检查vistor是否设置了cookie,如果没有,则将其重定向回第a.html页:

<script>
    if($.cookie('page_a_visited') !='true') {
        window.location.replace("/a.html");
    }
</script>

如果($.cookie('page\u a\u visted')!='true'){
window.location.replace(“/a.html”);
}

请给出一些简单的书面示例。感谢您提供上述详细答案。问题是如何使这个cookie只在sessiono上有效,直到浏览器关闭?设置cookie时只需删除选项的{expires:7,}部分。