1
Answer

How to first check cookie value then go to page?

Dawood Abbas

Dawood Abbas

9y
546
1
I want go to 'cart.aspx' page from 'country.apsx' by

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

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

Hide Copy Code
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";        
} 

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?
Answers (1)