Ajax載入外部頁面彈出層效果實現方法_AJAX相關

來源:互聯網
上載者:User

本文執行個體講述了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程式設計有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.