Highlighted

document.cookie not working in js for aem 6.3.2

Avatar

Avatar

Adobeaspirant

Avatar

Adobeaspirant

Adobeaspirant

26-07-2018

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 "";

Component is throwing "ReferenceError":Document is not defined error. How can we handle this?

Replies

Highlighted

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

26-07-2018

Hi,

It could be issue with your code calling before document load, but not sure.

could you try using jquery to get cookie if helps

e.g. alert( $.cookie("example") );

function getCookie(cname) {

    var name = cname + "=";

    alert($.cookie(name))

}

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

26-07-2018

Highlighted

Avatar

Avatar

Qamar_khan

Avatar

Qamar_khan

Qamar_khan

24-09-2018

Hello All,

         In this same context can you people help me how to get "login-token" in js in aem 6.3.

Thanks

Qamar