talkingD0G talkingD0G - 1 year ago 170
Javascript Question

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!

Answer Source

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

<!DOCTYPE html>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src=""></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() {
                        '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() {

<body onload='$("#yt").trigger("click");'>

        <h1>fancybox example</h1>
        <p><a id="yt" title="" href=";fs=1&amp;autoplay=1"></a></p>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download