demic0de
demic0de

Reputation: 1313

Jquery cookie not executing conditional statement

I've set the cookie to.

this is executed on click event.

  $("#scan").click(function(){
     $.cookie('scanner', true);
  });

Now when it is set I do something like this.

  $(document).ready(function(){

        var test = $.cookie('scanner');
        alert(test);
        if(test == true){

        setTimeout(function(){

            $("#scan").click();

        },10);
        }

});

Now when I open my page in new tab alert pops out saying it's true but not executing the click function. Why is that?

Thanks,

EDIT: ALSO how can i delete the cookie when i closed my tab not the browser?

Upvotes: 0

Views: 62

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382170

Your cookie value is saved and read as a string.

Try with

 if (test == "true") {

Upvotes: 3

Related Questions