document.cookie not working in js for aem 6.3.2 | Community
Skip to main content
Adobeaspirant
Level 3
Jul 26, 2018 1:53 PM UTC

document.cookie not working in js for aem 6.3.2

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

arunpatidar
New Participant
Jul 26, 2018 2:38 PM UTC

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))

}

Translate
Arun Patidar
smacdonald2008
Level 10
Jul 26, 2018 2:47 PM UTC

See this thread on this subject -- html - Set cookie and get cookie with JavaScript - Stack Overflow

Translate
Level 3
Sep 24, 2018 12:37 PM UTC

Hello All,

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

Thanks

Qamar

Translate