-1

我正在使用脚本在弹出窗口中播放我的 youtube 视频。是否可以更改此设置,以便我可以在弹出窗口中播放视频,但在下方添加 5 行文本作为有关视频的信息?

<script type="text/javascript">
    //<![CDATA[
    function showPopup(url) {
    newwindow=window.open(url,'name','height=315,width=560,top=200,left=300,resizable');
    newwindow.focus();
    }
    //]]>
</script>
4

1 回答 1

1
var win = window.open("", "win", "width=500,height=600"); // a window object
win.document.open("text/html", "replace");
win.document.write('<iframe width="420" height="315" src="http://www.youtube.com/embed/bKkESJ1abRA" frameborder="0" allowfullscreen></iframe><p>Your text</p><p>Hey, moar text :D</p>');
win.document.close();
win.focus();

尝试这个!

在评论中提出您的要求后:

<html>
    <head>
        <script>
            function openWindow(url,id){
                var win = window.open("", "win", "width=500,height=600"); // a window object
                var myText = document.getElementById(id).innerHTML;
                win.document.open("text/html", "replace");
                win.document.write('<iframe width="420" height="315" src="'+url+'" frameborder="0" allowfullscreen></iframe>'+myText);
                win.document.close(); 
            }

        </script>
    </head>
    <body>
        <img src="asd.jpg" onclick="openWindow('http://www.youtube.com/embed/bKkESJ1abRA','div1')">
        <img src="dsa.jpg" onclick="openWindow('http://www.youtube.com/embed/bKkESJ1abRA','div2')">
        <div style="display: none" id="div1">
            <p>My text 1</p>
        </div>
        <div style="display: none" id="div2">
            <p>My text 2</p>
        </div>
    </body>
</html>​

小提琴:http: //jsfiddle.net/BRAQD/

于 2012-12-06T09:31:54.537 回答