I am trying to get the cookies value in portal_normal.vm of my custom liferay theme.
At first I am setting a cookie value on click event using JavaScript. In some pages I able to get the cookies in theme but some pages I am not able to get the cookie value,but when I check in f12 cookies it is present.
Below is code for setting cookie using JavaScript:
$('.close').click(function(){
document.cookie = "cookie_set=true;path=/";
$('.close').attr("data-dismiss","alert");
});
Liferay custom theme to get the cookie:
#foreach($cookie in $request.getCookies())
#if ($cookie.getName() eq "cookie_set")
#set($previousWeb = $cookie.getValue())
#end
Problem here is I am able to get the cookie value in some pages.
Can any one help me out?
Thanks, Naresh.
try this
function getCookie(cname) {
var name = cname + "=";
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);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.