隐藏/如果cookie设置
我工作的透明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="&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 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="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=FL_Spot&autoPlay=true&autoRewind=false" />
<param name="swfversion" value="8,0,0,0" />
</object>';
...
我这样做,究竟但我得到的线58 Dreamweaver中的语法错误,这是此行的document.getElementById(” apDiv1')。innerHTML ='
此外,请尝试将闪光字符串一条线。这可能会让dw闭嘴。 –
视频在浏览器中根本没有显示出来 – Dan
我不认为这个问题与Java有什么关系。请更改标签。 – Kylo
当然,您可以使用removeChild函数通过JavaScript完全删除DIV,但您需要检查这是否适用于IE。或者更好地动态地写出你的div,就像Byron在他的回答中所建议的那样。 –
不要在JavaScript问题中使用'java'标记! http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java – BalusC