【发布时间】:2011-08-30 02:56:34
【问题描述】:
我正在努力将一个透明的 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>
【问题讨论】:
-
我认为这个问题与 Java 无关。请更改标签。
-
当然,您可以使用 removeChild 函数通过 JavaScript 完全删除 DIV,但您需要检查这是否适用于 IE。或者最好首先动态编写您的 div,正如 Byron 在他的回答中建议的那样。
-
不要使用
java标签来回答 JavaScript 问题! stackoverflow.com/questions/245062/…
标签: javascript html flash cookies