2014-01-07 63 views
0

在下面的iframe中,你會看到一個<object>在與#videoPlayerSWF的ID,在底部(我包括以防萬一,iframe代碼的其餘部分)是否有可能在此iframe中覆蓋<object>的寬度和高度?

通過JS,我曾嘗試選擇它,操縱寬度以及由iframe的javascript設置的元素的高度,以匹配窗口的寬度和高度。

下面是我失敗的JS嘗試。不管是什麼,我不能覆蓋的#videoPlayerSWF

window.onload = function(){ 
    document.getElementById("videoPlayerSWF").height='100%'; 
    document.getElementById("videoPlayerSWF").width='100%'; 
} 

什麼是測試如果它甚至可以在所有覆蓋它的好辦法值是多少?

<iframe id="musicVideo" width="100%" height="100%" type="text/html" src="http://cache.vevo.com/m/html/embed.html?video=GBA320903400" frameborder="0"> 


    <html xmlns="http://www.w3.org/1999/xhtml"><head> 
      <title>VEVO EMBED IFRAME</title> 
      <script src="http://cache.vevo.com/a/js/lib/swfobject.js" type="text/javascript"></script> 
      <script type="text/javascript" src="http://cache.vevo.com/m/js/embed.js"></script> 
      <script type="text/javascript" src="http://cache.vevo.com/m/js/jquery-1.7.1.min.js"></script> 
      <script type="text/javascript" src="http://adm.fwmrm.net/p/Vevo_chromeless_wrapper/AdManager.js"></script> 
      <script type="text/javascript" src="http://livepassdl.conviva.com/ver/2.50.0.56856/LivePass.js?customerId=c3.Vevo"></script> 
      <script type="text/javascript"> 
       $(document).ready(function() { selectEmbed(); }); 
      </script> 
      <style type="text/css"> 

       #videoPlayerHTML5, #wrapper, #playerHTML5, #playerSWF 
       { 
        width:100%; 
        height:100%; 
        margin:0px; 
        padding:0; 
        background-color:#000000; 
       } 

       html 
       { 
        width:100%; 
        height:100%; 
        overflow:hidden; 
       } 

       body 
       { 
        height:100%; 
        margin:0px; 
        padding:0; 
       } 

       #video_overlay { 
        position:absolute; 
        z-index:19790119; 
        opacity:0.4; 
         filter:alpha(opacity=40); 
         top: 20px; 
         right: 20px; 
       } 

      </style> 
     </head> 
     <body> 
      <script type="text/javascript"> 

       function selectEmbed() { 
        switch (getParameter("forceSelect")) { 
         case "0": 
          $("#playerHTML5").hide(); 
          embedSwf(); break; 
         case "1": 
          $("#playerSWF").hide(); 
          initializeHTML5(); break; 
         default: 
          embedDynamicVideo(); break; 
        } 
       } 

       function embedDynamicVideo() { 
        var video = getParameter("video"); 
        var playlist = getParameter("playlist") || false; 
        var autoplay = getParameter("autoplay") || "0"; 
        var playerType = getParameter("playerType") || "embedded"; 
        var cultureName = getParameter("cultureName") || "en_us"; 
        var cultureIsRTL = getParameter("cultureIsRTL") || "False"; 
        var embed = getParameter("embed"); 
        var sbId = getParameter("sbId") || "C188A3CA-3593-453A-B995-394B7A7E5332"; 
        var siteSection = getParameter("siteSection") || "vevo_player_embedded"; 

        vevoEmbed.embedDynamicVideo(video, siteSection, sbId, $("#playerHTML5"), $("#videoPlayerHTML5"), "playerSWF", "videoPlayerSWF", $("#playerSWF").width(), $("#playerSWF").height()); 
       } 

       function initializeHTML5() { 
        var sbId = getParameter("sbId") || "C188A3CA-3593-453A-B995-394B7A7E5332"; 
        var video = getParameter("video"); 
        var autoplay = getParameter("autoplay") || "0"; 
        var addAuto = (autoplay == "1"); 

        if (addAuto) { 
         $('videoPlayerHTML5').attr('autoPlay', true); 
        } 
        var siteSection = getParameter("siteSection") || "vevo_player_embedded"; 
        vevoEmbed.embedVevoVideo(video, siteSection, sbId, $('#playerHTML5'), $('#videoPlayerHTML5')); 
       } 

       function getParameter(sParam) { 
        var sPageURL = window.location.search.substring(1); 
        var sURLVariables = sPageURL.split('&'); 
        for (var i = 0; i < sURLVariables.length; i++) { 
         var sParameterName = sURLVariables[i].split('='); 
         if (sParameterName[0] == sParam) { 
          return sParameterName[1]; 
         } 
        } 
       } 

       function embedSwf() { 

        var video = getParameter("video"); 
        var playlist = getParameter("playlist") || false; 
        var autoplay = getParameter("autoplay") || "0"; 
        var playerType = getParameter("playerType") || "embedded"; 
        var cultureName = getParameter("cultureName") || "en_us"; 
        var cultureIsRTL = getParameter("cultureIsRTL") || "False"; 
        var embed = getParameter("embed"); 
        var sbId = getParameter("sbId") || "C188A3CA-3593-453A-B995-394B7A7E5332"; 
        var siteSection = getParameter("siteSection") || "vevo_player_embedded"; 


        var environment = getParameter("branch"); 
        var baseurl = "" 
        switch (environment) { 
         case 'local': baseurl = "http://localhost:3086"; break; 
         case 'staging': baseurl = "http://stg-videoplayer.vevo.com"; break; 
         default: baseurl = "http://videoplayer.vevo.com"; break; 
        } 

        swfobject.embedSWF(baseurl + "/embed/embedded", "playerSWF", "100%", "100%", "10.1.53", false, { /*flashvars*/ 
         'playerType': playerType, 
         'videoId': video, 
         'playlist': playlist, 
         'enableDomScan': 'false', 
         'siteSection': siteSection, 
         'autoplay': autoplay, 
         'cc': "US", 
         'cultureName': cultureName, 
         'cultureIsRTL': cultureIsRTL, 
         'embed': embed, 
         'endScreen': 'play', 
         'sbId': sbId 
        }, { /*params*/ 
         bgcolor: "#000000", 
         allowFullScreen: "true", 
         allowScriptAccess: "always", 
         wmode: "transparent" 
        }, { /*attributes*/ 
         id: "videoPlayerSWF" 
        }); 
       } 
      </script> 
      <object type="application/x-shockwave-flash" id="videoPlayerSWF" data="http://videoplayer.vevo.com/embed/embedded" width="924" height="835"><param name="bgcolor" value="#000000"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"><param name="flashvars" value="playerType=embedded&amp;videoId=GBA320903400&amp;playlist=false&amp;enableDomScan=false&amp;siteSection=vevo_player_embedded&amp;autoplay=0&amp;cc=US&amp;cultureName=en_us&amp;cultureIsRTL=False&amp;embed=&amp;endScreen=play&amp;sbId=C188A3CA-3593-453A-B995-394B7A7E5332"></object> 
      <div id="playerHTML5" style="display: none;"> 
       <div id="video_overlay"> 
        <img src="http://stg-m.vevo.com/m/img/logo/vevo_logo_white.png"> 
       </div> 
       <video id="videoPlayerHTML5"></video> 
      </div> 


     </body></html> 
    </iframe> 

回答

1

您無法通過來自另一個域(本例中爲vevo.com)的javascript操作或定位iframe內容。

但是,即使你能,你必須針對相應的window對象(內嵌框架),而不是父網站運行在全局窗口:

var iframe = document.getElementById('musicVideo'); 
var iframe_window = iframe.contentWindow; 
iframe_window.document.getElementById("videoPlayerSWF").height='100%'; 
// etc 

但正如所說,這不會,如果工作iframe src在另一個域上。