Replaying a Video

Discussion in 'HTML & Website Design' started by BobL, May 27, 2006.

  1. #1
    Hi,

    I've been asked by a client who owns the following website http://www.brooksgrouplimited.com/ if its possible to make the video of the actor only play once when each visitor enters the site. If they then select one of the sub options and press BACK to return to the original page he doesn't want the video to play.

    If they visit the site at a later time he wants the video to play once again.

    Hope this makes sense. I don't know of a way but is this possible?

    Thanks in advance

    Bob
     
    BobL, May 27, 2006 IP
  2. johneva

    johneva Well-Known Member

    Messages:
    1,480
    Likes Received:
    46
    Best Answers:
    1
    Trophy Points:
    170
    #2
    Yes this can be done by making a cookie and then making it only play if the page has not been visited before but it would take some programming knowlage. ;)

    Here is an example of a cookie being used to only have a popup on first vist.

    http://javascript.internet.com/cookies/only-popup-once.html
     
    johneva, May 28, 2006 IP
  3. BobL

    BobL Well-Known Member

    Messages:
    680
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Cheers but they want to play the video every time someone visits the site even if they have visited before. They don't want to play it if the user has gone back to the home page by pressing the BACK key etc.

    I suppose they could store a date and time in the cookie which didn't play it if it was during the last 20 minutes or so.

    You can probably tell i'm not really a programmer.
     
    BobL, May 28, 2006 IP
  4. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Here's one thing you can do. When the page is initially loaded you can check to see if the user came from an external site (such as Google), or if they manually typed your site's address in, or if they've come from an internal link (from within your site). If they're coming from an external site (or they manually typed your site in), the video will play, if not, the video will not play. If they click on a link on your page, a played flag will be recorded (noting that the video has been "played") and that flag will be saved as a cookie. When the user clicks the back button and returns to your page, the presence of the played cookie is detected. If it's found, the video won't play (because it's already been played). For this to work, you have to set up your page so that it doesn't cache itself the first time the page is viewed (this way we can make sure the page is fully reloaded when the user clicks the back button). Here's the code to do it...

    Put this in your <head> section...
    
     <meta http-equiv="cache-control" content="no-cache" />
     <meta http-equiv="pragma" content="no-cache" />
     <meta http-equiv="expires" content="0" />
     <script type="text/javascript">
     <!--
      window.onload = on_load;
      window.onunload = on_un_load;
      function on_load() {
       if (document.referrer == '' || document.referrer.indexOf('brooksgrouplimited.com') == -1) {
        document.cookie = 'played=0'; // user came from external site
       }
       else {
        document.cookie = 'played=1'; // user came from internal link
       }
      }
      function on_un_load() { document.cookie = 'played=1'; }
      function play_video() { return (document.cookie.indexOf('played=1') == -1) ? true : false; }
     // -->
     </script>
    
    Code (markup):
    Then, further down the page (right below your video code) put this code in...
    
     <script type="text/javascript">
     <!--
      if (play_video()) {
       // place code here to start the video in auto-play mode
    
    
      }
      else {
       // place code here to start the video in paused mode
    
       
      }
     //-->
     </script>
    
    Code (markup):
     
    brian394, Jun 6, 2006 IP