简体   繁体   English

如果设置了cookie,则隐藏/删除Div

[英]Hide/Remove Div if cookie is set

I am working to add a transparent flash video to a site of a person walking out. 我正在努力为一个走出去的人的网站添加一个透明的Flash视频。 The problem is that I don't want the video to play every time the home page is loaded, so I set a 24hr cookie that if detected the div containing the video is set to hide. 问题是我不希望每次加载主页时都播放视频,所以我设置了一个24小时的cookie,如果检测到包含视频的div被设置为隐藏。 This works perfectly in Google Chrome and FF, the problem is in IE the div is apparently hidden because you cannot see the video but the audio of the video is still heard. 这在谷歌Chrome和FF中完美运行,问题是在IE中,div显然是隐藏的,因为你看不到视频,但仍然可以听到视频的音频。 Perhaps there is a different way to do this then the way I am going about it and maybe even a way to do a remove instead of hide? 也许有一种不同的方式可以做到这一点然后我的方式,甚至可能是一种方法来删除而不是隐藏? If anyone has any suggestions it would be very much appreciated. 如果有人有任何建议,将非常感谢。

//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>

Just write to the div dynamically. 只需动态写入div。

Change the div to be empty 将div更改为空

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

Write the flash from the IF statement. 从IF语句中写入闪存。 (You could do this using dom) (你可以用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>';

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM