Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

document.cookie not working in js for aem 6.3.2

Avatar

Avatar
Validate 1
Level 3
Adobeaspirant
Level 3

Likes

21 likes

Total Posts

59 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
Adobeaspirant
Level 3

Likes

21 likes

Total Posts

59 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Adobeaspirant
Level 3

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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))

}

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

26-07-2018

Avatar

Avatar
Validate 1
Level 3
Qamar_khan
Level 3

Likes

17 likes

Total Posts

30 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
Level 3
Qamar_khan
Level 3

Likes

17 likes

Total Posts

30 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile
Qamar_khan
Level 3

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