views:

387

answers:

2

I want to show Popup window contain YouTube video. My question is how to resize YouTube Player when user resize the Popup Window ?

Head section of Popup windows PHP/HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Wavin Video</title>

<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

    //If the User resizes the window
    //$(window).bind("resize", resizeWindow);
    $(window).resize(resizeWindow).resize()
    function resizeWindow( e ) {
        var target = "#youtubebox2";
        var newWindowHeight = $(window).height();
        var newWindowWidth  = $(window).width();

        console.log("Width : "+newWindowWidth);
        console.log("Height: "+newWindowHeight);
        console.log("---------");

        $(target).html("<object width=\""+newWindowWidth+"\" height=\""+newWindowHeight+"\" id=\"youtubebox\"><param name=\"movie\" value=\"http://www.youtube.com/v/&lt;?php echo $_GET['filename'];?>\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/&lt;?php echo $_GET['filename'];?>\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\""+newWindowWidth+"\" height=\""+newWindowHeight+"\"></embed></object>");
    }

});

</script>

</head>
<body>
<div align="center" style="padding:6px 0px 0px 0px;background-color: #ccc;" id="youtubebox2">

<object width="480" height="385" id="youtubebox">
<param name="movie" value="http://www.youtube.com/v/&lt;?php echo $_GET['filename'];?>"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/&lt;?php echo $_GET['filename'];?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385">
</embed>
</object>

</div>
</body>
</html>

the page receive youtube video ID through $_GET variable.

the code above didn't work, the YouTUbe Player is not resized. Is there something I miss ?

+1  A: 

I just miss ; sign

Permana
A: 

Still, why rewrite the whole of the object html instead of updating the objects height/width?

$("object, embed").height($(window).height());
$("object, embed").width($(window).width());

on second thought, why not just set height/width to 100%?

JKirchartz
I just found out this way, thanks for the information. The first way works. But the second way, video's high is not going 100%
Permana