Rich-text Reply

Make an action after 3 clicks on a element

miguelm 12-29-15

Make an action after 3 clicks on a element

Hi,

 

I have the following code to close a window and set a cookie when the user closes the window, but I want set the cookie only the third time that the window is closed- How can I do this?

 

Thank you

 

 

$(document).on('click','.close',function(){
    $(this).parent().hide("slow"); //This should happen always
    document.cookie="my_cookie=cookie"; //This only should happen the third time
});
Level 2

JDahlinANF 12-29-15
 

Re: Make an action after 3 clicks on a element

@miguelm - 3 times in one page, or 3 times total?

If 3 times in one page, have your click function increment a counter and create the cookie when the counter reaches 3,

 

If 3 times ever, you'll need to use either a cookie or sessionStorage or localStorage to track the counter across pages (note, storages are limited in that they are unique per tab, subdomain, and even http vs https).

miguelm 01-04-16
 

Re: Make an action after 3 clicks on a element

Thank you @nap0leon should be three times ever, so I'm going to try it using tracking the counter in the cookie.

Level 2
JDahlinANF 01-04-16
 

Re: Make an action after 3 clicks on a element

[ Edited ]

@miguelm - if you have the means, you could add the cookie code outside of the Optimizely experiment and set up an Audience that looks for the value of that cookie.  That way your experiment would only contain users who are eligible to be affected by the experiment.

miguelm 01-04-16
 

Re: Make an action after 3 clicks on a element

Hi,
the experiment consists in show a pop-up, what I want is show the pop-up only three times, i am going to try the option of the create a counter in the cookie, and when the value is >3 don't show the pop-up.

Thank you!
Level 2