posts - 20,  comments - 2,  trackbacks - 0

作者: tianshi0253  链接:http://tianshi0253.javaeye.com/blog/205000  发表时间: 2008年06月18日

声明:本文系JavaEye网站发布的原创博客文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!

<!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><title>-</title>
<style>
body {margin:0px}
#Loading {position:absolute;z-index:10;left:10px;top:10px;border:1px #666666 solid;background:#eeeeee;width:10px;height:10px}
.LoadContent {width:100%;height:100%;overflow:auto}
</style>
<script LANGUAGE="JavaScript"> 
<!-- 
function $(){return document.getElementById?document.getElementById(arguments[0]):eval(arguments[0]);}
var OverH,OverW,ChangeDesc,ChangeH=50,ChangeW=50;
function OpenDiv(_Dw,_Dh,_Desc) {
$("Loading").innerHTML="Loading...";
OverH=_Dh;OverW=_Dw;ChangeDesc=_Desc;
$("Loading").style.display='';
if(_Dw>_Dh){ChangeH=Math.ceil((_Dh-10)/((_Dw-10)/50))}else if(_Dw<_Dh){ChangeW=Math.ceil((_Dw-10)/((_Dh-10)/50))}
$("Loading").style.top=(document.documentElement.clientHeight-10)/2+"px";
$("Loading").style.left=(document.documentElement.clientWidth-10)/2+"px";
OpenNow()
}
var Nw=10,Nh=10;
function OpenNow() {
if (Nw>OverW-ChangeW)ChangeW=2;
if (Nh>OverH-ChangeH)ChangeH=2;
Nw=Nw+ChangeW;Nh=Nh+ChangeH;

if(OverW>Nw||OverH>Nh) {
	if(OverW>Nw) {
	$("Loading").style.width=Nw+"px";
	$("Loading").style.left=(document.documentElement.clientWidth-Nw)/2+"px";
	}
	if(OverH>Nh) {
	$("Loading").style.height=Nh+"px";
	$("Loading").style.top=(document.documentElement.clientHeight-Nh)/2+"px"
	}
	window.setTimeout("OpenNow()",10)
	}else{
	Nw=10;Nh=10;ChangeH=50;ChangeW=50;
	AjaxGet(ChangeDesc)
	}
}

//创建XML对象
function createXMLHttps(){
var ret = null;
try {ret = new ActiveXObject('Msxml2.XMLHTTP')}
catch (e) {
	try {ret = new ActiveXObject('Microsoft.XMLHTTP')}
        catch (ee) {ret = null}
	}
if (!ret&&typeof XMLHttpRequest !='undefined') ret = new XMLHttpRequest();
return ret;
}

function AjaxGet(URL) {
var xmlhttp = createXMLHttps();
xmlhttp.open("Get",URL,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status==404) {$("Loading").innerHTML='读取页面失败,文件'+URL+'不存在!';return}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		$("Loading").innerHTML="<div class='LoadContent'>"+xmlhttp.responseText+"</div>";
		}
	}
xmlhttp.send(null);
}
//-->
</script> 
</head>
<body>
由于不能跨域,读取的文件须在同一域名下,如果出现错误,<br>原因是在目标文件上的,本例代码本身没有错误<br>
<font color=red>如果目标文件数据过大,花费的时间也相对较长,外部文件需用utf-8编码,否则中文可能显示为乱码</font>
<br><br>
  <a href="javascript:OpenDiv(500,300,'forum-1-1.html')">forum-1-1.html 500*300</a><br><br>
  <a href="javascript:OpenDiv(500,200,'faq.php')">faq.php 500*200</a><br><br>
  <a href="javascript:OpenDiv(200,500,'1.html')">1.html 200*500</a><br><br>
  <a href="javascript:OpenDiv(500,500,'2.html')">2.html 500*500</a><br><br>
双击关闭层
<div id="Loading" style="display:none" ondblclick="this.style.display='none'"></div>
</body>
</html>

 


本文的讨论也很精彩,浏览讨论>>


JavaEye推荐




文章来源:http://tianshi0253.javaeye.com/blog/205000
posted on 2008-06-18 09:14 姚文超 阅读(412) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: