Ajax加载外部页面弹出层效果实现方法
程序员文章站
2022-06-14 15:21:25
本文实例讲述了ajax加载外部页面弹出层效果实现方法。分享给大家供大家参考。具体实现方法如下:
本文实例讲述了ajax加载外部页面弹出层效果实现方法。分享给大家供大家参考。具体实现方法如下:
<!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=utf-8" /> <title>ajax加载外部页面的一个弹出层效果</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> <a href="javascript:opendiv(500,300,'index.html')">首页 500*300</a><br><br> <a href="javascript:opendiv(500,200,'index.html')">test 500*200</a><br><br> <a href="javascript:opendiv(200,500,'l.html')">子页面 200*500</a><br><br> <div id="loading" style="display:none" ondblclick="this.style.display='none'"></div> 注意:需加载的文件必须在子目录下,也就是本文件需处于上级才行。页面编码utf8。 </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。