对这个问题的奇怪格式表示歉意。我最近问了几个类似的问题,但仍然不知所措。我真的不知道其中大部分是如何工作的,我一直在尝试遵循 W3Schools.com 等地方的各种教程等,并在这里的人们的帮助下,虽然我不完全理解,但我认为我快到了。
我想做的只是在访问者第一次到达该网站时播放一段视频(但它有点特殊 - 它是透明的,并且需要 float 在页面上)。
如果 cookie 不存在,下面的代码会正确设置 cookie,并在访问该站点的用户上检查它。我遇到的问题是以下行的语法:
document.getElementById('video').innerHTML =
如果我评论该行,所有其他 cookie 内容都可以正常工作,所以我希望有人可以提供帮助。 Firefox 错误控制台给出的错误是: xml 源意外结束并且 checkCookie 未定义
我也尝试过在整个过程中引用引号,但这并没有真正的区别。
这是代码,提前谢谢大家。罗布。
<div id="video" style="position:absolute;top:125px;left:-67px;z-index:10000000"> </div>
<script src="AC_RunActiveContent.js" type="text/javascript"> </script>
<script type="text/javascript">
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x = x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function setCookie(c_name,value,exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");
if (username!=null && username!="")
{
setCookie("username",username,7);
document.getElementById('video').innerHTML = <script type="text/javascript"> AC_FL_RunContent ('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer')</script>;
}
}
}
</script>
<body onload="checkCookie()">
</body>
最佳答案
你是不是少了几个引号?
document.getElementById('video').innerHTML = <script type="text/javascript"> AC_FL_RunContent ('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer')</script>;
vs
document.getElementById('video').innerHTML = "<script type='text/javascript'> AC_FL_RunContent ('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer')</script>";
关于javascript - 使用inner.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7549149/