1

I have a div element that shows up after 20 second of video play.If you will play the video after 20 second of play a div will shows up. Now I want to set cookie so that if the div have been shown once ,it keeps on showing unless the user clear the cache (cookie logic).

This is what I have tried so far - 

http://jsfiddle.net/9L29o365/

How can this be achieved?

Thanks In Advance .

Sahil Dhir
  • 3,857
  • 1
  • 10
  • 30

2 Answers2

1

Try this code

set cookie

Cookies.set('div-20sec', 'visited');

get cookie

var val=Cookies.get('div-20sec');

DEMO

Amal
  • 3,255
  • 1
  • 8
  • 17
0

You could set the cookie in your onPlayProgress function, and read the same cookie handle in your click play listener:

// set 
document.cookie='20secSet=true';
// get
var cookieVal =  document.cookie
                         .split(',')
                         .indexOf('20secSet=true');

Here's an example using your code.

mrtig
  • 1,982
  • 13
  • 20
  • ok I am new to cookie method.. can you explain how it works.. and also I see the red div hidden everytime I loads.. even if I had played it once – Sahil Dhir May 16 '17 at 05:41
  • You can find sufficient documentation [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie). The principle is setting the value in the cookie bag, then having to parse out the value you are interested in later. There are additional options related to expiry. – mrtig May 16 '17 at 05:45
  • Can you describe how you are not able to produce the red box after playing the video for 20 seconds? – mrtig May 16 '17 at 05:46
  • I am able to produce the red box.. Not able able to retain it when iI reload the page. – Sahil Dhir May 16 '17 at 06:14