Ravi
Ravi

Reputation: 717

Make Condition in JS Cookie

Both SetCookie() and GetCookie() works good.

Problem:

make condition IF cookie value Not NULL then BOX show Continues otherwise HIde.

I have run bellow code but condition not going true.

    $(document).ready(function(){
        var first_name = getCookie("chat_name");
        var user_id = getCookie("chat_id");
        var img_src = getCookie("chat_img");

        if(first_name !=="" && user_id !=="" && img_src !=="")
           // if(document.cookie.length > 0)
         {
           $("#chat_output").show();
           $("#hidebox").show();
           $("#chat_store").show();
           $("#chat_box").show();
         }

});

For Delete Cookie i used bellow code.its works good

    document.cookie ="chat_id=''";
    document.cookie ="chat_name=''";
    document.cookie ="chat_img=''"; 

Can you suggest me how i can solved this issue.

Thank You

Upvotes: 0

Views: 844

Answers (1)

Helpful
Helpful

Reputation: 706

if (getCookie("cookie-name")===null){ /* code to show box */ }

Should do what you're looking for.

Upvotes: 1

Related Questions