如何首先检查cookie值然后转到页面? [英] How to first check cookie value then go to page?

查看:91
本文介绍了如何首先检查cookie值然后转到页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从'country.apsx'转到'cart.aspx'页面



I want go to 'cart.aspx' page from 'country.apsx' by

<a id="linkCart" href="cart.aspx">cart</a>





但在'cart.aspx'我正在检查cookie值





but in 'cart.aspx' i am checking cookie value by

var userCookie = getCookie('loggedInUser');
        function getCookie(name) {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
            }
            return null;
        }
        if (userCookie == null) {
            window.location.href = "loginpage.aspx";
        }





然后如果cookie值为null则必须去'login.aspx'页面,否则加载'cart.aspx '仅限页面



但是当我点击'购物车'(锚标签)时,首先显示购物车页面,然后在条件成真后显示loading.aspx页面..



其中必须直接显示'login.aspx'页面而不显示'cart.aspx'页面。那怎么办?



then if cookie value null then have to go 'login.aspx' page otherwise load this 'cart.aspx' page only

but when I click on 'cart' (anchor tag) then first displaying cart page then displaying loading.aspx page after condition is get true..

where as have to display directly 'login.aspx' page without display 'cart.aspx' page. so what to do?

推荐答案

在cart.aspx中加载页面时检查cookie
Check for the cookie when the page load in cart.aspx


然后你应该检查一下country.aspx本身的cookie。



为购物车链接添加JavaScript点击事件处理程序。



In点击事件,检查cookie是否存在。如果找到,请转到cart.aspx,否则转到login.aspx。
Then you should check the cookie in country.aspx itself.

Add a JavaScript click event handler for cart link.

In that click event, check if cookie exists or not. If found, go to cart.aspx, else go to login.aspx.


这篇关于如何首先检查cookie值然后转到页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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