IE8 窗体浮动报错为“对象不支持此属性或方法”
小弟写了网上弄了段DIV层代码弄到自己的.aspx页面上面,原本浮动的代码在HTML中是完全正常的,附加到aspx页面上以后,就发现在其他其他浏览器,火狐,Opera,chrome上面都能实现窗体的浮动,唯独在IE上面不行,IE8上面显示的是“对象不支持此属性或方法”,求助各位大神们!谢谢!!
具体代码如下:
<%@ Page Language="vb" ContentType="text/html" ResponseEncoding="gb2312" CodeBehind="help.aspx.vb" AutoEventWireup="false" Inherits="localhost.help" %>
<%@ Register TagPrefix="uc1" TagName="top" Src="top.ascx" %>
<%@ Register TagPrefix="uc1" TagName="bottom" Src="bottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ad" Src="ad.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML >
<HEAD>
<title>帮助</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="css/css.css">
<link type="text/css" rel="stylesheet" href="css/css1.css"/>
<script type="text/javascript" src="admin/js/js.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<script type="text/javascript" src ="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" src="js/jquery.scroll-follow.js"></script>
<%--QQ客服的javascript--%>
<script type="text/javascript">
$(function(){
$('#divStayTopleft').scrollFollow({
speed:1000,
//offset: 156,
//relativeTo:"bottom",
killSwitch: "switchlink",
onText: '取消滚动',
offText: '开启滚动'
});
});
</script>
<SCRIPT language=javascript>
var online= new Array();
if (!document.layers)
document.write('<div id="divStayTopLeft" style="position:absolute; clear:both;">')
</SCRIPT>
<script type="text/javascript">
var verticalpos="frombottom"
if (!document.layers)
document.write('</div>')
function JSFX_FloatTopDiv()
{
var startX =screen.width-140,
startY = 220;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.left=x;this.style.top=y;};
el.x = startX;
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopLeft=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 10);
}
ftlObj = ml("divStayTopLeft");
stayTopLeft();
}
JSFX_FloatTopDiv();
function CloseQQ()
{
divStayTopleft.style.display="none";
return true;
}
</script>
<script type="text/javascript">
window.onload=function(){
yanzheng()
}
function xianshi(a){
var b=document.getElementById("xx").getElementsByTagName("div")
for(var i=0;i<b.length;i++){
if(b[i].id!=="clear"){
b[i].style.display="none"
}
}
document.getElementById(a).style.display="block"
}
</script>
</HEAD>
<body>
<%--新增的QQ客服模块--%>
<div id="divStayTopleft" style=" POSITION: absolute">
//div内的内容省略掉了。
</div>
</body>
[解决办法]
你这代码也太老了,还判断document.layers,NS浏览器早在7-8年前都消亡了,
你可以使用
兼容IE6/IE7/IE8/IE9/Firefox/Chrome/Safari/Oprea浏览器的浮动代码
<%@ Page Language="C#" %><!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><style type="text/css">html,body{margin:0;padding:0;}#y1 {position:fixed;top:0;left:0;width:100px;height:100px;border:1px solid red;}#y2 {position:fixed;top:0;right:0;width:100px;height:100px;border:1px solid red;}#y3 {position:fixed;bottom:0;left:0;width:100px;height:100px;border:1px solid red;}#y4 {position:fixed;bottom:0;right:0;width:100px;height:100px;border:1px solid red;}</style><!--[if lte IE 6]><style>#y1 {position:absolute;}#y2 {position:absolute;}#y3 {position:absolute;}#y4 {position:absolute;}</style><![endif]--><script type="text/javascript"> //以下所有脚本只为IE6写,其他浏览器完全可以删除。 function getViewportScrollX() { var scrollX = 0; if (document.documentElement && document.documentElement.scrollLeft) { scrollX = document.documentElement.scrollLeft; } else if (document.body && document.body.scrollLeft) { scrollX = document.body.scrollLeft; } else if (window.pageXOffset) { scrollX = window.pageXOffset; } else if (window.scrollX) { scrollX = window.scrollX; } return scrollX; } function getViewportScrollY() { var scrollY = 0; if (document.documentElement && document.documentElement.scrollTop) { scrollY = document.documentElement.scrollTop; } else if (document.body && document.body.scrollTop) { scrollY = document.body.scrollTop; } else if (window.pageYOffset) { scrollY = window.pageYOffset; } else if (window.scrollY) { scrollY = window.scrollY; } return scrollY; } function getViewportWidth() { var width = 0; if (document.documentElement && document.documentElement.clientWidth) { width = document.documentElement.clientWidth; } else if (document.body && document.body.clientWidth) { width = document.body.clientWidth; } else if (window.innerWidth) { width = window.innerWidth - 18; } return width; } function getViewportHeight() { var height = 0; if (window.innerHeight) { height = window.innerHeight - 18; } else if (document.documentElement && document.documentElement.clientHeight) { height = document.documentElement.clientHeight; } else if (document.body && document.body.clientHeight) { height = document.body.clientHeight; } return height; } if (navigator.userAgent.indexOf("MSIE 6") > -1 && navigator.userAgent.indexOf("MSIE 7") == -1 && navigator.userAgent.indexOf("MSIE 8") == -1) { window.ononload = window.onscroll = window.onresize = function (e) { var t = getViewportScrollY(); var l = getViewportScrollX(); var w = getViewportWidth(); var h = getViewportHeight(); document.getElementById("y1").style.left = l + "px"; document.getElementById("y1").style.top = t + "px"; document.getElementById("y2").style.left = l + w - document.getElementById("y2").offsetWidth + "px"; document.getElementById("y2").style.top = t + "px"; document.getElementById("y3").style.left = l + "px"; document.getElementById("y3").style.top = t + h - document.getElementById("y2").offsetHeight + "px"; document.getElementById("y4").style.left = l + w - document.getElementById("y2").offsetWidth + "px"; document.getElementById("y4").style.top = t + h - document.getElementById("y2").offsetHeight + "px"; } }</script></head><body><div id="y1">左上角位置的内容</div><div id="y2">右上角位置的内容</div><div id="y3">左下角位置的内容</div><div id="y4">右下角位置的内容</div><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p></body></html>