views:

73

answers:

3

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!

A: 

May you use a fancybox ?

Here is a link for it - http://fancybox.net/api

Kapil
This might work but how to do I implement it on page load? I'm not a javascript coder at all.
s_broderick
A: 
<script type="text/javascript">
    $(document).ready(function() {
        $("#trigger").fancybox().trigger('click');
    });
</script>

Put your link #trigger somewhere in your document and hide it using css.

EDIT

<!DOCTYPE html>
<html>
<head>
    <!-- Css -->
    <link href="/path/to/fancybox.css" rel="stylesheet" type="text/css" />

    <!-- Javascript -->
    <script src="/path/to/jquery.js" type="text/javascript"></script>
    <script src="/path/to/fancybox.js" type="text/javascript"></script>

    <script type="text/javascript">
           $(document).ready(function() {
               $("#trigger").fancybox().trigger('click');
           });
    </script>        
</head>
<body>

    <!--hide trigger using display:none -->
    <p style="display:none"><a href="path/to/youtube" id="trigger"></a></p>

</body>
</html>

Here is the howto: http://fancybox.net/howto

gearsdigital
Can you give me an example of how to tell the link to auto-open on page load?
s_broderick
I've edited my answer above.
gearsdigital
I added the code and am making progress. The loading image is up but it's not loading the path. I placed the YouTube link in it because I'm not sure how to use the embed with that code.Here's my code:<script type="text/javascript"> $(document).ready(function() { $("#trigger").fancybox().trigger('click'); }); </script></head><body><p style="display:none"><a href="http://www.youtube.com/watch?v=2y8G7wMgIPY" id="trigger"></a></p>
s_broderick
+1  A: 

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"&gt;&lt;/script&gt;
    <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;amp;fs=1&amp;amp;autoplay=1"&gt;&lt;/a&gt;&lt;/p&gt;
</body>
</html>
gearsdigital
That's PERFECT! Thank you so much!
s_broderick
You're welcome.
gearsdigital