使用jquery将javascript(for Quicktime)插入<div> </div>

时间:2009-05-31 14:00:44

标签: javascript html

我对javascript和编程很陌生,并且在我的项目中碰到了一堵砖墙。我有一个包含javascript的div来嵌入一个quicktime播放器,当页面首次加载时,页面没有指向.mov文件,所以占位符div是'unhidden'而播放器div设置为style.display = 'none'

到目前为止,用户输入了新电影的名称,占位符div被隐藏,播放器div被取消隐藏。我的问题是,当div被设为可见时,播放器div中的javascript没有运行,如果我让播放器的脚本成为一个单独的函数,然后在播放器div被取消隐藏时调用它然后播放器全屏运行而不是在div。

我尝试使用jquery在div显示后将javascript添加到div中,但似乎无法让$("#player").load(somescript)$("#player").html(htmlwithjavain)添加脚本。

我知道玩家div contenst可以更改,因为我可以使用$("#player").empty();$("#player").html();来操纵它。

感谢您阅读,希望您能提供帮助

以下是相关代码: -

<html>
    <head>
        <title>Browse Media Player</title>


                <link rel="stylesheet" type="text/css" href="CSS/browser.css" />

        <script type="text/javascript">

        <!--

                var userinterrupt=false;
                var runonce=false;

                var currentfile;
                var basemediapath = "http://10.255.10.71/IsilonBrowse/movfiles/";

                var playerheight = 750;
                var playerwidth = 900;

                var currenttc;
                var basetime;
                var baseduration;
                var currentduration = "no tc available";
                var tcoffset = 35990;

                var playspeed = 1;
                var boolisplaying=true;
                var boolonslide=false;



                //function to fire off other methods when the DOM is loaded
                //Use in place of body onload, using jquery library
                //

            $(document).ready(function()
                {
                  //showEvents('jquery running');
                  showhideplayer(null);
                });




              //-->
             </script>


    </head>
    <body onload="forceslider(); timecode()">



      <div class="container">

           <div id="timecode_container">
                <div class="tc_overlay"></div>
                <div id="timecode" class="timecode"></div>
           </div>

           <div id="player" class="playerdiv" style="display:none;">

               **javascript for player goes here...**

           </div>

           <div id="noclipoverlay" class="playerdiv" style="display:none;">
           <p>No media loaded...
           </div>

           <div id="noclipoverlay2" class="playerdiv" style="display:none;">
           <p>loading media....
           </div>

      </div>


        <div id="loadstatus"></div>
        <div id="alerts"></div>

    </body>
</html>

现在应该添加javascript代码的mainstuff.js文件: -

         //function to switch the player div and mask div is no media file is
         //defined in the 'currentfile' variable
         //
         function showhideplayer(state)
         {

          if (!currentfile)
          {
                showEvents('wtf no media');
                document.getElementById("player").style.display = 'none';
                document.getElementById("noclipoverlay").style.display = 'block';
          }

          else if (currentfile)
          {

           document.getElementById("player").style.display = 'block';
           document.getElementById("noclipoverlay").style.display = 'none';
           showEvents('valid media file');

           }

           }

            //end of showhideplayer



         //function to change movie files, note SetResetPropertiesOnReload must be set to false
         //otherwise the B'stard player will default all attributes when setURL runs
         //
         function changemovie(newmovie)
         {
            oldfile = currentfile;
            if (newmovie == currentfile)
            {
              showEvents('same file requested so no action taken');
              return;
            }

            if (newmovie != currentfile)
            {
              showEvents('changing movie');
              //switch the divs around to hide the 'no media slide'
              document.getElementById("player").style.display = 'block';
              document.getElementById("noclipoverlay").style.display = 'none';
            }


            showEvents('movie changed to: '+newmovie);
            currentfile=newmovie;

            if (!oldfile)
            {
              $("#player").empty();
              showEvents('the old media file was blank');

              $("#player").load("/path/loadplayer.js");



            }

            document.movie1.Stop();
            document.movie1.SetResetPropertiesOnReload(false);
            document.movie1.SetURL(currentfile);

            //showEvents('movie changed to: '+newmovie);

            if (boolisplaying)
            {
              document.movie1.Play();
            }

         }

[编辑]这里是loadplayer.js的内容: -

            var movie1 = QT_WriteOBJECT(
        currentfile, playerwidth, playerheight, "",
        "controller","false",
        "obj#id", "movie1",
        "emb#id","qt_movie1",
        "postdomevents","True",
        "emb#NAME","movie1",
            "enablejavascript","true",
        "autoplay","true",
        "scale","aspect",
        "pluginspage","http://www.apple.com/quicktime/download/"
            );

2 个答案:

答案 0 :(得分:2)

在不知道loadplayer.js文件的内容的情况下,很难为您提供解决方案。

例如,如果脚本在页面加载后尝试执行document.write(),它将创建一个新页面,覆盖当前页面。当你说quicktime电影全屏运行时,你的意思是什么?

加载SCRIPT元素并将其作为HTML插入通常也不是一个好主意。当您向页面添加HTML时,jQuery会查找所有SCRIPT元素并在全局上下文中对它们进行评估,这可能会给您带来意想不到的结果。

答案 1 :(得分:0)

如果您想要返回字符串,请使用AC_QuickTime.js中的QT_GenerateOBJECTText_XHTML或QT_GenerateOBJECTText。