2012-09-19 51 views
2

我注意到,當使用任何典型的隱藏div的方法在Safari瀏覽器中無法使用YouTube視頻時。看看這個基本webpage-無法隱藏Safari瀏覽器中的youtube iframe?

<!DOCTYPE html> 
<html> 
<head><title>Safari Test</title></head> 
<body> 
<div id="test"> 
<iframe width="560" height="315" src="http://www.youtube.com/embed/Nry5zSJxG9k" frameborder="0" allowfullscreen></iframe> 
</div> 
<div id="safari" style="display: none;"> 
<iframe width="560" height="315" src="http://www.youtube.com/embed/Nry5zSJxG9k" frameborder="0" allowfullscreen></iframe> 
</div> 
</body> 
</html> 

現在的DIV是隱藏的,但試試這在Safari這 - 查看和打開開發者工具。如果你去Safari瀏覽器並點擊顯示,那麼視頻將會重新出現。現在,再次點擊它隱藏它,你會注意到它並沒有隱藏。爲什麼這會成爲一個問題,你可能想知道?好吧,我正在爲youtube視頻製作旋轉木馬,並通過隱藏不活動的視頻來工作。在Safari 5.1.7的最佳理由版本中,視頻根本不會消失。有沒有人知道這個問題的解決辦法?我試着用不透明度,高度,寬度和可見度來隱藏它,但你仍然可以在Safari中看到它。有人有主意嗎? iframe的

回答

0

空src屬性,當你隱藏DIV document.getElementById("iframetab").setAttribute("src","");並設置該屬性時,你會顯示DIV document.getElementById("iframetab").setAttribute("src","www.google.com");
給予iframe的ID。

5

我試着用不透明度,高度,寬度和可見度來隱藏它,但你仍然可以在Safari中看到它。有人有主意嗎?

您是否嘗試將iframe從屏幕上移開?

position: absolute; 
left: -10000px; 
top: -10000px; 
+0

這是正確的答案。 – tfont

0

我試過幾個途徑來解決Safari一直iframe出現的問題,這其中似乎工作,同時保持對其他瀏覽器一致的行爲:

function Hide_Handler(oEvent) 
{ 
    try 
    { 
     $('#iframecontainer').css 
     ({ 
     background : {?} // Where ? == color, loading image, whatever.. 
     }) 
     .find('.iframeClass').css // http://stackoverflow.com/a/12503745/1257652 
     ({ 
     position : "absolute", 
     left  : "-10000px", 
     top  : "-10000px" 
     }); 
    } 
    catch (ex) { } 
} 

function Show_Handler(oEvent) 
{ 
    try 
    { 
     $('#iframecontainer').css 
     ({ 
     background : "" // Where ? == color, loading image, whatever.. 
     }) 
     .find('.iframeClass').css // http://stackoverflow.com/a/12503745/1257652 
     ({ 
     position : "", 
     left  : "", 
     top  : "" 
     }); 
    } 
    catch (ex) { } 
} 

和一個小竅門,我發現滾動iframe以及具有iframe容器元素的原因:

#iframeContainer 
{ 
    height : (n)px; // Where n is a number 
    width : (n)px; // Where n is a number 
    overflow : auto; 
} 

.iframeClass 
{ 
    margin : 0px; 
    padding : 0px; 
    width : 100%; 
    height : 99%; 
    border : none; 
    overflow : hidden; 
} 
1

簽出未記錄的'wmode':'t ransparent'像這樣....

player = new YT.Player('player', { 
     height: '476', 
     width: '400', 
     videoId: 'yourvidhere', 
     playerVars: { 
      'autoplay': 0, 
       'controls': 0, 
       'rel': 0, 
       'showinfo': 0, 
       'modestbranding': 1, 
      'wmode': 'transparent' 
     }, 
     events: { 
      'onReady': onPlayerReady, 
      'onStateChange': onPlayerStateChange 
     } 
    }); 
+0

簡單,爲我工作。 – Jon

相關問題