木子屋 Dnawo's BLOG

IE6.0下广告代码离奇消失之谜

👤 dnawo 📅 2009-07-20 👁 4531 👍 0 💬 0 🔄 来源:本站原创
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AD</title>
</head>

<body>
<script type="text/javascript">
var div = document.createElement("div");
div.style.position = "absolute";
div.innerHTML = "<img src='http://img1.gtimg.com/news/pics/19354/19354360.jpg' border='0' />";
try{document.getElementsByTagName("body").item(0).appendChild(div)}catch(ex){};

div.style.top = "300px";
div.style.left = "300px";
</script>
</body>
</html>

上边代码在IE6.0运行效果:首页打开页面,广告显示一会后自动消失,刷新一下则无此问题。经过多次测试,发现:

1).注释掉最后两句不会有自动消失的问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AD</title>
</head>

<body>
<script type="text/javascript">
var div = document.createElement("div");
div.style.position = "absolute";
div.innerHTML = "<img src='http://img1.gtimg.com/news/pics/19354/19354360.jpg' border='0' />";
try{document.getElementsByTagName("body").item(0).appendChild(div)}catch(ex){};

[color=Red]//div.style.top = "300px";
//div.style.left = "300px";[/color]
</script>
</body>
</html>

2).给div设置背景色后也不会有自动消失的问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AD</title>
</head>

<body>
<script type="text/javascript">
var div = document.createElement("div");
div.style.position = "absolute";
div.innerHTML = "<img src='http://img1.gtimg.com/news/pics/19354/19354360.jpg' border='0' />";
[color=Red]div.style.backgroundColor = "#000000";[/color]
try{document.getElementsByTagName("body").item(0).appendChild(div)}catch(ex){};

div.style.top = "300px";
div.style.left = "300px";
</script>
</body>
</html>

具体原因未知:(

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 FF下无法移动元素解决方法 下一篇 → 游泳姿势图解