-1

I am a beginner in web development, i want put a youtube iframe with autoplay, but just for the first visit, using something cookie or variable for control it.

When i visit the site for the second time, the video wont autoplay.

Is it posible?

1 Answers1

1

Logic should be easy. When a user visits the website, check the user has the cookie. If not, assign him the cookie. If yes, do nothing.

And on adding parameters to Youtube Iframe, you should check the cookie is set or not and depending on that add the autoplay parameter.

The below links will help and have the complete solution you are looking for. I am not reinventing the solution since they are already been posted.

Youtube Documentation:

https://developers.google.com/youtube/player_parameters

For Setting and Retrieving Cookie with Vanilla JavaScript:

Set cookie and get cookie with JavaScript

Harish ST
  • 1,475
  • 9
  • 23