Setting Cookies in browser for video autoplay

前端 未结 3 1785
陌清茗
陌清茗 2021-01-07 08:21

How would I set cookies such that a video only plays automatically on the first visit only, afterwards if they want to watch it, it must be played manually?

3条回答
  •  猫巷女王i
    2021-01-07 08:53

    Per Justin808's answer, the general idea would be like this:

    if (!cookieIsSet()) {
      setCookie();
      playMovie();
    }
    

    See the W3Schools site for an example use of cookies similar to what you want to achieve: http://www.w3schools.com/js/js_cookies.asp

    If you are embedding a YouTube video you could do it like this:

    
    
    
    

    Obviously, you would have to define your own cookieIsSet() and setCookie() functions. See the W3School's site for examples how.

提交回复
热议问题