我正在努力将透明的 Flash 视频添加到一个人走出去的网站。问题是我不希望每次加载主页时都播放视频,所以我设置了一个 24 小时 cookie,如果检测到包含视频的 div,则设置为隐藏。这在 Google Chrome 和 FF 中完美运行,问题是在 IE 中,div 显然是隐藏的,因为您看不到视频,但仍然可以听到视频的音频。也许有一种不同的方法可以做到这一点,而不是我正在做的事情,甚至可能是一种删除而不是隐藏的方法?如果有人有任何建议,我们将不胜感激。
//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="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=FL_Spot&autoPlay=true&autoRewind=false" />
<param name="swfversion" value="8,0,0,0" />
</object>
</div>
最佳答案
只需动态写入 div。
将div改成空
<div id="apDiv1"> </div>
从 IF 语句写入 flash。 (你可以使用 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="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=FL_Spot&autoPlay=true&autoRewind=false" />
<param name="swfversion" value="8,0,0,0" />
</object>';
...
关于javascript - 如果设置了 cookie,则隐藏/删除 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7234083/