2011-08-29 124 views
3

我工作的透明Flash視頻添加到一個人走了的網站刪除事業部。問題是我不希望每次加載主頁時播放視頻,所以我設置了一個24小時的cookie,如果檢測到包含該視頻的div被設置爲隱藏。這在谷歌瀏覽器和FF完美的作品,問題是在IE的div顯然隱藏,因爲你看不到視頻,但視頻的音頻仍然聽到。也許有不同的方式來做到這一點,然後我就這樣做,甚至可以做一個刪除而不是隱藏的方式?如果有人有任何建議,將非常感激。隱藏/如果cookie設置

//div that holds the video 
<style type="text/css"> 
#apDiv1 { 
position: fixed; 
width:560px; 
height:314px; 
z-index:100; 
left: 452px; 
top: 316px; 
} 
</style> 

    <script type="text/javascript"> 
function createCookie(name,value,days) { 
if (days) { 
    var date = new Date(); 
    date.setTime(date.getTime()+(days*24*60*60*1000)); 
    var expires = "; expires="+date.toGMTString(); 
} 
else var expires = ""; 
document.cookie = name+"="+value+expires+"; path=/"; 
} 

function readCookie(name) { 
var nameEQ = name + "="; 
var ca = document.cookie.split(';'); 
for(var i=0;i < ca.length;i++) { 
    var c = ca[i]; 
    while (c.charAt(0)==' ') c = c.substring(1,c.length); 
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
} 
return null; 
} 

function eraseCookie(name) { 
createCookie(name,"",-1); 
} 

function setTheDivStyle() { 
if(!readCookie('wroteIt')) { 
// if cookie not found display the div and create the cookie 
document.getElementById("apDiv1").style.display="block"; 
createCookie('wroteIt', 'wroteIt', 1); // 1 day = 24 hours persistence 
} 
else { 
// if cookie found hide the div 
document.getElementById("apDiv1").style.display="none"; 
} 
} 
</script> 

</head> 
<body onload = "setTheDivStyle()"> 

<div id="apDiv1"> 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="560" height="314" id="FLVPlayer"> 
    <param name="movie" value="FLVPlayer_Progressive.swf" /> 
    <param name="quality" value="high" /> 
    <param name="wmode" value="transparent" /> 
    <param name="scale" value="noscale" /> 
    <param name="salign" value="lt" /> 
    <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=Clear_Skin_1&amp;streamName=FL_Spot&amp;autoPlay=true&amp;autoRewind=false" /> 
    <param name="swfversion" value="8,0,0,0" /> 
    </object> 
</div> 
+0

我不認爲這個問題與Java有什麼關係。請更改標籤。 – Kylo

+0

當然,您可以使用removeChild函數通過JavaScript完全刪除DIV,但您需要檢查這是否適用於IE。或者更好地動態地寫出你的div,就像Byron在他的回答中所建議的那樣。 –

+0

不要在JavaScript問題中使用'java'標記! http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java – BalusC

回答

2

只需動態寫入div即可。

更改股利空

<div id="apDiv1"> </div> 

寫的IF語句閃光燈。 (你可以使用dom來做到這一點)

... 
if(!readCookie('wroteIt')) { 
// if cookie not found display the div and create the cookie 

document.getElementById('apDiv1').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="560" height="314" id="FLVPlayer"> 
    <param name="movie" value="FLVPlayer_Progressive.swf" /> 
    <param name="quality" value="high" /> 
    <param name="wmode" value="transparent" /> 
    <param name="scale" value="noscale" /> 
    <param name="salign" value="lt" /> 
    <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=Clear_Skin_1&amp;streamName=FL_Spot&amp;autoPlay=true&amp;autoRewind=false" /> 
    <param name="swfversion" value="8,0,0,0" /> 
    </object>'; 

... 
+0

我這樣做,究竟但我得到的線58 Dreamweaver中的語法錯誤,這是此行的document.getElementById(」 apDiv1')。innerHTML =' - – Dan

+0

此外,請嘗試將閃光字符串一條線。這可能會讓dw閉嘴。 –

+0

視頻在瀏覽器中根本沒有顯示出來 – Dan