Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cross Browser Fixed - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.divClass {
position:fixed;
border:1px solid gray;
color:#ccc;
top:200px;
left:5px;
background-color:#666;
}
</style>
<script type="text/javascript">
function openDiv(){
var newDiv=document.createElement("div");
newDiv.style.width="400px";
newDiv.style.height="400px";
newDiv.style.backgroundColor="#488be8";
newDiv.className = 'divClass';
document.body.appendChild(newDiv);
};
</script>
<!--[if lte IE 6]>
<script type="text/javascript">
function fixedIE(tl, n){
var sc='scroll'+tl, d=document, c='compatMode';
return d[c] && d[c]=='CSS1Compat'? d.documentElement[sc]+n+'px' : d.body[sc]+n+'px';
}
</script>
<style type="text/css">
body {
background:url(foo) fixed;
}
.divClass {
position:absolute;
top:expression(fixedIE('Top',200));
left:expression(fixedIE('Left',5));
}
</style>
<![endif]-->
</head>
<body>
<input type="button" value="click me it will Create Dynamic Div how to make it fix in IE6" onclick="return openDiv();">
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
</body>
</html>
Or, if you want to use just javascript:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cross Browser Fixed - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function openDiv(){
var newDiv = document.createElement('div'), s = newDiv.style;
s.border = '1px solid gray';
s.color = '#ccc';
s.width = '400px';
s.height = '400px';
s.backgroundColor = '#488be8';
s.top = '200px';
s.left = '200px';
s.position = 'fixed';
if(typeof fixedIE == 'function'){
s.position = 'absolute';
s.setExpression('top', "fixedIE('Top',200)");
s.setExpression('left', "fixedIE('Left',200)");
document.body.style.background = 'url(foo) fixed';
};
document.body.appendChild(newDiv);
};
</script>
<!--[if lte IE 6]>
<script type="text/javascript">
function fixedIE(tl, n){
var sc='scroll'+tl, d=document, c='compatMode';
return d[c] && d[c]=='CSS1Compat'? d.documentElement[sc]+n+'px' : d.body[sc]+n+'px';
}
</script>
<![endif]-->
</head>
<body>
<input type="button" value="click me it will Create Dynamic Div how to make it fix in IE6" onclick="return openDiv();">
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
<p>Other Content</p>
</body>
</html>
Bookmarks