我正在努力为一个走出去的人的网站添加透明的Flash视频。问题是我不希望每次加载主页时都播放视频,所以我设置了一个24小时的cookie,如果检测到包含视频的div被设置为隐藏。这在谷歌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>
答案 0 :(得分:2)
只需动态写入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>';
...