javascriptjqueryvideolightboxshadowbox

Opening a YouTube video in a lightbox or something on page load


My client wants a YouTube video (embeded object) to popup when a user comes to their site.

Does anyone know how it do this and what to use. It should be a lightbox or shadowbox, something that's not a popup.

The video should run automatically and ideally close when it's over. Maybe I can specify a time until auto-close or something?

Please help. Thanks all!


Solution

  • This is a full working solution. Just copy this html. Don't forget to change the path to the js and css.

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title></title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.1.js"></script>
        <link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.1.css" media="screen" />
    
        <script type="text/javascript">
            $(document).ready(function() {
    
                $("#yt").click(function() {
                    $.fancybox({
                            'padding'        : 0,
                            'autoScale'      : false,
                            'transitionIn'   : 'none',
                            'transitionOut'  : 'none',
                            'title'          : this.title,
                            'width'          : 680,
                            'height'         : 495,
                            'href'           : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                            'type'           : 'swf',
                            'swf'            : {
                                'wmode'              : 'transparent',
                                'allowfullscreen'    : 'true'
                            }
                        });
                    return false;
                });
            });
            $('#foo').bind('click', function() {
                  alert($(this).text());
                });
                $('#foo').trigger('click');
        </script>
    </head>
    
    <body onload='$("#yt").trigger("click");'>
    
            <h1>fancybox example</h1>
            <p><a id="yt" title="" href="http://www.youtube.com/watch?v=2y8G7wMgIPY&amp;fs=1&amp;autoplay=1"></a></p>
    </body>
    </html>